<?php

declare(strict_types=1);

namespace App\Observers;

use App\Models\SickLeave;
use App\Services\Leave\LeaveDaysCalculator;

class SickLeaveObserver
{
    public function __construct(
        private readonly LeaveDaysCalculator $leaveDaysCalculator,
    ) {}

    public function saving(SickLeave $sickLeave): void
    {
        if ($sickLeave->start_date === null || $sickLeave->end_date === null) {
            return;
        }

        $sickLeave->days = $this->leaveDaysCalculator->between(
            $sickLeave->start_date,
            $sickLeave->end_date,
        );
    }
}
