<?php

namespace App\Http\Requests;

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

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

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

        $routeSpecificRules = [
            'rolescreens.update' => [
                'fk_office' => ['required', 'integer', 'min:1'],
                'fk_role' => ['required', 'integer', 'min:1'],
                'role_screens' => ['required', 'array', 'min:1'],
                'role_screens.*.id' =>  ['required', 'integer', 'min:1'],
                'role_screens.*.permission' => ['required', 'boolean'],
                'role_screens.*.parent' => ['required', 'boolean']
            ],
            'rolescreens.getRolePermissions' => [
                'fk_office' => ['required', 'integer', 'min:1'],
                'fk_role' => ['required', 'integer', 'min:1']
            ],
        ];

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