<?php

namespace App\Services;

use App\Models\ProviderWorkingDay;
use Illuminate\Database\Eloquent\Collection;

class ProviderWorkingDayService
{
    public function getByProvider(int $providerId): Collection
    {
        return ProviderWorkingDay::where('provider_id', $providerId)->get();
    }

    public function findByDayAndPeriod(int $providerId, int $day, string $period): ?ProviderWorkingDay
    {
        return ProviderWorkingDay::where('provider_id', $providerId)
            ->where('day', $day)
            ->where('period', $period)
            ->first();
    }

    public function create(array $data): ProviderWorkingDay
    {
        return ProviderWorkingDay::create($data);
    }

    public function delete($id, $day, $period): bool
    {
        $workingDay = ProviderWorkingDay::where('provider_id', $id)
            ->where('day', $day)
            ->where('period', $period)
            ->first();

        return $workingDay ? $workingDay->delete() : false;
    }
}
