<?php

namespace Modules\HR\Services;

use Illuminate\Support\Facades\DB;
use Modules\HR\DTO\HrSettingFilter;
use Modules\HR\Models\LeaveType;
use Modules\HR\Repositories\LeaveTypeRepository;

class LeaveTypeService
{
    protected $leaveTypeRepo;

    public function __construct(LeaveTypeRepository $leaveTypeRepo)
    {
        $this->leaveTypeRepo = $leaveTypeRepo;
    }

    public function list(HrSettingFilter $filter)
    {
        $columns = [
            'id',
            'name',
            'days_per_year',
            'is_paid',
            'is_encashable',
            'status'
        ];
        return $this->leaveTypeRepo->all($filter, $columns);
    }

    public function lookup(HrSettingFilter $filter)
    {
        $columns = ['id', 'name', 'status'];
        return $this->leaveTypeRepo->all($filter, $columns);
        
    }

    public function show($id)
    {
        return $this->leaveTypeRepo->find($id);
    }

    public function store(array $data)
    {
        return DB::transaction(function () use ($data) {
            return $this->leaveTypeRepo->create($data);
        });
    }

    public function update(LeaveType $leaveType, array $data)
    {
        return DB::transaction(function () use ($leaveType, $data) {
            return $this->leaveTypeRepo->update($leaveType, $data);
        });
    }

    public function updateStatus(LeaveType $leaveType, array $status)
    {
        return DB::transaction(function () use ($leaveType, $status) {
            return $this->leaveTypeRepo->updateStatus($leaveType, $status);
        });
    }
}
