<?php

namespace App\Actions\Menu;

use App\DTOs\MenuData;
use App\Events\ModelChanged;
use App\Models\Menu;
use App\Repositories\Contracts\MenuRepositoryInterface;

final class UpdateMenuAction
{
    public function __construct(private MenuRepositoryInterface $repository) {}

    public function execute(Menu $menu, MenuData $data): Menu
    {
        $result = $this->repository->update($menu, $data->toArray());

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

        return $result;
    }
}
