<?php
namespace Modules\HR\Services;

use Illuminate\Support\Facades\DB;
use Modules\HR\DTO\HrSettingFilter;
use Modules\HR\Models\HolidayGroup;
use Modules\HR\Repositories\HolidayGroupRepository;

class HolidayGroupService
{
    protected $holidayGroupRepo;

    public function __construct(HolidayGroupRepository $holidayGroupRepo) {
        $this->holidayGroupRepo = $holidayGroupRepo;
    }

    public function list(HrSettingFilter $filter)
    {
        $columns = ['id', 'name', 'status'];

        return $this->holidayGroupRepo->all($filter, $columns);
    }

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

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

    public function update(HolidayGroup $holidayGroup, array $data)
    {
        return DB::transaction(function () use ($holidayGroup, $data) {
            return $this->holidayGroupRepo->update($holidayGroup, $data);
        });
    }

    public function updateStatus(HolidayGroup $holidayGroup, array $status)
    {
        return DB::transaction(function () use ($holidayGroup, $status) {
            return $this->holidayGroupRepo->updateStatus($holidayGroup, $status);
        });
    }

}
