<?php

namespace Modules\Employee\Repositories;

use Modules\Core\Enums\StatusEnum;
use Modules\Employee\DTO\EmployeeSettingFilter;
use Modules\Employee\Models\EmployeeHolidayGroup;

class EmpHolidayGroupRepository
{
    public function all(EmployeeSettingFilter $filter, array $columns = ['*'], array $relations = [])
    {
        return EmployeeHolidayGroup::query()
            ->select($columns)
            ->search($filter->search)
            ->with($relations)
            ->filterByEmployee($filter->employee_id)
            ->filterStatus($filter->status ?? '')
            ->paginate($filter->perPage ?? 15);
    }

    public function find($id)
    {
        $empHolidayGroup = EmployeeHolidayGroup::findOrFail($id);
        return $empHolidayGroup;
    }

    public function assign(array $data)
    {
        $empHolidayGroup = EmployeeHolidayGroup::create([
            'employee_id' => $data['employee_id'],
            'holiday_group_id' => $data['holiday_group_id'],
            'assigned_from' => $data['assigned_from'],
            'assigned_to' => $data['assigned_to'],
            'status'     => $data['status'] ?? StatusEnum::ACTIVE,
        ]);

        return $empHolidayGroup;
    }
}
