<?php

namespace App\Actions\Course;

use App\DTOs\CourseData;
use App\Events\ModelChanged;
use App\Models\Course;
use App\Repositories\Contracts\CourseRepositoryInterface;

class UpdateCourseAction
{
    public function __construct(private CourseRepositoryInterface $repository) {}

    public function execute(Course $course, CourseData $data): Course
    {
        /** @var Course */
        $result = $this->repository->update($course, $data->toArray());

        ModelChanged::dispatch(Course::class, 'updated');

        return $result;
    }
}
