<?php

namespace Modules\Employee\Services;

use Modules\Employee\Repositories\ShiftRepository;
use Modules\Employee\DTO\EmployeeSettingFilter;
use Illuminate\Support\Facades\DB;
use Modules\Employee\Models\Shift;

class ShiftService
{
    protected $shiftRepo;

    public function __construct(ShiftRepository $shiftRepo)
    {
        $this->shiftRepo = $shiftRepo;
    }
    public function lookUpList(EmployeeSettingFilter $filter)
    {
        $columns = ['id', 'name', 'status'];

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


    public function list(EmployeeSettingFilter $filter)
    {
        $columns = ['id', 'name', 'start_time', 'end_time', 'late_after', 'grace_minutes', 'min_work_minutes', 'overtime_after_minutes', 'is_night_shift', 'status'];

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

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

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

    public function update(Shift $shift, array $data)
    {
        return DB::transaction(function () use ($shift, $data) {
            return $this->shiftRepo->update($shift, $data);
        });
    }

    public function updateStatus(Shift $shift, array $status)
    {
        return DB::transaction(function () use ($shift, $status) {
            return $this->shiftRepo->updateStatus($shift, $status);
        });
    }
}
