<?php

namespace App\Actions\Announcement;

use App\DTOs\AnnouncementData;
use App\Events\ModelChanged;
use App\Models\Announcement;
use App\Repositories\Contracts\AnnouncementRepositoryInterface;

final class CreateAnnouncementAction
{
    public function __construct(private AnnouncementRepositoryInterface $repository) {}

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

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

        return $result;
    }
}
