<?php

namespace App\Http\Requests;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        $baseRules = [];

        $routeSpecificRules = [
            'screens.index' => [
                'fk_site' => ['required', 'integer', 'min:1'],
            ],
            'screens.parents' => [
                'fk_office' => ['required', 'nullable', 'integer', 'min:1'],
            ],
            'screens.store' => [
                'screenname' => ['required', 'string', 'min:2', 'max:25'],
                'url' => ['required', 'string', 'min:1', 'max:35'],
                'icon' => ['required', 'string', 'min:2', 'max:35'],
                'fk_parent' => ['nullable', 'integer', 'min:1'],
                'sortorder' => ['required', 'integer', 'min:1'],
            ],
            'screens.update' => [
                'id' => ['required', 'integer', 'min:1'],
                'screenname' => ['required', 'string', 'min:2', 'max:25'],
                'url' => ['required', 'string', 'min:1', 'max:35'],
                'icon' => ['required', 'string', 'min:2', 'max:35'],
                'fk_parent' => ['nullable', 'integer', 'min:1'],
                'sortorder' => ['required', 'integer', 'min:1'],
            ],
            'screens.updateStatus' => [
                'id' => ['required', 'integer', 'min:1'],
                'available' => ['required', 'boolean'],
            ],
            'screens.updateVisibility' => [
                'id' => ['required', 'integer', 'min:1'],
                'visible' => ['required', 'boolean'],
            ],
            'screens.destroy' => [
                'id' => ['required', 'integer', 'min:1'],
            ],
            'screens.userMenu' => [
                'fk_office' => ['required', 'nullable', 'integer', 'min:1'],
            ],
            'screens.hasPermisson' => [
                'fk_office' => ['required', 'nullable', 'integer', 'min:1'],
                'screenname' => ['required', 'string'],
            ],
        ];

        $currentRoute = Route::currentRouteName();

        return array_merge($baseRules, $routeSpecificRules[$currentRoute] ?? []);
    }
}
