<?php

namespace App\Http\Requests\Menu;

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

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

    /**
     * @return array<string, array<int, mixed>>
     */
    public function rules(): array
    {
        return [
            'label' => ['required', 'string', 'max:255'],
            'url' => ['required', 'string', 'max:255'],
            'location' => ['required', 'string', Rule::enum(MenuLocation::class)],
            'type' => ['required', '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 [
            'label.required' => 'Menü etiketi zorunludur.',
            'url.required' => 'URL zorunludur.',
            'location.required' => 'Menü konumu zorunludur.',
            'type.required' => 'Menü tipi zorunludur.',
            'parent_id.exists' => 'Üst menü bulunamadı.',
        ];
    }
}
