<?php

namespace App\Actions\Faq;

use App\DTOs\FaqData;
use App\Events\ModelChanged;
use App\Models\Faq;
use App\Repositories\Contracts\FaqRepositoryInterface;

final class CreateFaqAction
{
    public function __construct(private FaqRepositoryInterface $repository) {}

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

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

        return $result;
    }
}
