<?php

namespace App\Actions\HeroSlide;

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

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

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

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

        return $result;
    }
}
