<?php

namespace App\Actions\HeroSlide;

use App\DTOs\HeroSlideData;
use App\Events\ModelChanged;
use App\Models\HeroSlide;
use App\Repositories\Contracts\HeroSlideRepositoryInterface;

final class UpdateHeroSlideAction
{
    public function __construct(private HeroSlideRepositoryInterface $repository) {}

    public function execute(HeroSlide $heroSlide, HeroSlideData $data): HeroSlide
    {
        $result = $this->repository->update($heroSlide, $data->toArray());

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

        return $result;
    }
}
