<?php

namespace App\Actions\Announcement;

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

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

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

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

        return $result;
    }
}
