<?php

namespace App\Services;

use App\Models\CustomScheduleSpeciality;

class CustomScheduleSpecialityService
{
    public function getAll()
    {
        return CustomScheduleSpeciality::with(['customSchedule', 'speciality'])
            ->orderBy('created_at', 'desc')
            ->get();
    }

    public function getById($id)
    {
        return CustomScheduleSpeciality::with(['customSchedule', 'speciality'])->findOrFail($id);
    }

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

    public function update($id, array $data)
    {
        $customScheduleSpeciality = CustomScheduleSpeciality::findOrFail($id);

        $customScheduleSpeciality->update($data);

        return $customScheduleSpeciality->fresh(['customSchedule', 'speciality']);
    }

    public function delete($id)
    {
        $customScheduleSpeciality = CustomScheduleSpeciality::findOrFail($id);

        $customScheduleSpeciality->delete();

        return $customScheduleSpeciality;
    }

    //

    public function getByCustomScheduleId($customScheduleId)
    {
        return CustomScheduleSpeciality::with(['speciality'])
            ->where('custom_schedule_id', $customScheduleId)
            ->get();
    }
}
