<?php

namespace App\Repositories\Admin;

use App\Models\Unit;
use InfyOm\Generator\Common\BaseRepository;

/**
 * Class UnitRepository
 * @package App\Repositories\Admin
 * @version December 15, 2021, 11:53 pm UTC
 *
 * @method Unit findWithoutFail($id, $columns = ['*'])
 * @method Unit find($id, $columns = ['*'])
 * @method Unit first($columns = ['*'])
*/
class UnitRepository extends BaseRepository
{
    /**
     * @var array
     */
    protected $fieldSearchable = [
        'name',
        'unit_head_id',
        'created_at'
    ];

    /**
     * Configure the Model
     **/
    public function model()
    {
        return Unit::class;
    }

    /**
     * @param $request
     * @return mixed
     */
    public function saveRecord($request)
    {
        $input = $request->all();
        $unit = $this->create($input);
        return $unit;
    }

    /**
     * @param $request
     * @param $unit
     * @return mixed
     */
    public function updateRecord($request, $unit)
    {
        $input = $request->all();
        $unit = $this->update($input, $unit->id);
        return $unit;
    }

    /**
     * @param $id
     * @return mixed
     */
    public function deleteRecord($id)
    {
        $unit = $this->delete($id);
        return $unit;
    }
}
