<?php

namespace Modules\HR\Services;

use Illuminate\Support\Facades\DB;
use Modules\HR\DTO\HrSettingFilter;
use Modules\HR\Models\AttendancePolicy;
use Modules\HR\Repositories\AttendancePolicyRepository;

class AttendancePolicyService
{
    protected $attendancePolicyRepo;

    public function __construct(AttendancePolicyRepository $attendancePolicyRepo)
    {
        $this->attendancePolicyRepo = $attendancePolicyRepo;
    }

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

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

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

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

    public function update(AttendancePolicy $attendancePolicy, array $data)
    {
        return DB::transaction(function () use ($attendancePolicy, $data) {
            return $this->attendancePolicyRepo->update($attendancePolicy, $data);
        });
    }

    public function updateStatus(AttendancePolicy $attendancePolicy, array $status)
    {
        return DB::transaction(function () use ($attendancePolicy, $status) {
            return $this->attendancePolicyRepo->updateStatus($attendancePolicy, $status);
        });
    }
}
