<?php

namespace App\Actions\Faq;

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

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

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

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

        return $result;
    }
}
