<?php

namespace App\Actions\Menu;

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

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

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

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

        return $result;
    }
}
