<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class LeafSetting extends Model
{
    use HasFactory;

    protected $hidden = ['user_id'];

    private static function saveBasicInfo($leaf, $request)
    {
        $leaf->leaf_type = $request->leaf_type;
        $leaf->total_number = $request->total_number;
        $leaf->save();

        return $leaf;
    }

    public static function newLeaf($request)
    {
        $leaf = new self;
        $leaf->user_id = Auth::id();

        return self::saveBasicInfo($leaf, $request);
    }

    public static function updateLeaf($request, $id)
    {
        return self::saveBasicInfo(self::query()->find($id), $request);
    }
}
