<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Services\SidebarMenuService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class MenuFavoriteController extends Controller
{
    public function __construct(
        private SidebarMenuService $sidebarMenuService
    ) {}

    public function toggle(Request $request): JsonResponse
    {
        $request->validate([
            'menu_id' => 'required|integer|exists:menus,id',
        ]);

        $result = $this->sidebarMenuService->toggleFavorite(
            auth()->id(),
            $request->integer('menu_id')
        );

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

    public function reorder(Request $request): JsonResponse
    {
        $request->validate([
            'menu_ids' => 'required|array',
            'menu_ids.*' => 'integer',
        ]);

        $this->sidebarMenuService->reorderFavorites(
            auth()->id(),
            $request->input('menu_ids')
        );

        return response()->json(['success' => true]);
    }
}
