<?php

namespace App\Domains\Menu\Controllers;

use App\Domains\Menu\Models\Menu;
use App\Domains\Menu\Requests\StoreTenantMenuRequest;
use App\Domains\Menu\Services\TenantMenuService;
use App\Domains\Tenant\Models\Tenant;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

class TenantMenuController extends Controller
{
    public function __construct(private readonly TenantMenuService $tenantMenuService) {}

    public function store(
        StoreTenantMenuRequest $request,
        string $tenantCode,
        string $menuCode,
    ): JsonResponse {
        $tenant = Tenant::query()->where('codigo', $tenantCode)->firstOrFail();
        $menu = Menu::query()->where('code', $menuCode)->firstOrFail();

        $tenantMenu = $this->tenantMenuService->configure(
            $tenant,
            $menu,
            $request->validated('static_content'),
        );

        return response()->json($tenantMenu);
    }
}
