<?php

namespace App\Http\Requests\Menu;

use App\Enums\MenuLocation;
use App\Enums\MenuType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateMenuRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    /**
     * @return array<string, array<int, mixed>>
     */
    public function rules(): array
    {
        return [
            'label' => ['sometimes', 'string', 'max:255'],
            'url' => ['sometimes', 'string', 'max:255'],
            'location' => ['sometimes', 'string', Rule::enum(MenuLocation::class)],
            'type' => ['sometimes', 'string', Rule::enum(MenuType::class)],
            'parent_id' => ['nullable', 'integer', 'exists:menus,id'],
            'order_index' => ['sometimes', 'integer', 'min:0'],
            'is_active' => ['sometimes', 'boolean'],
        ];
    }

    /**
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'parent_id.exists' => 'Üst menü bulunamadı.',
        ];
    }
}
