<?php

namespace App\Actions\Schedule;

use App\DTOs\ScheduleData;
use App\Events\ModelChanged;
use App\Models\CourseSchedule;
use App\Repositories\Contracts\ScheduleRepositoryInterface;

final class CreateScheduleAction
{
    public function __construct(private ScheduleRepositoryInterface $repository) {}

    public function execute(ScheduleData $data): CourseSchedule
    {
        $result = $this->repository->create($data->toArray());

        ModelChanged::dispatch(CourseSchedule::class, 'created');

        return $result;
    }
}
