<?php

namespace App\Http\Requests;

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

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

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

        $routeSpecificRules = [
            'configurations.index' => [
                'fk_site' => ['required', 'integer', 'min:1'],
            ],
            'configurations.store' => [
                'fk_site' => ['required', 'integer', 'min:1'],
                'name' => ['required', 'string', 'min:3'],
                'type' => ['required', 'string', 'min:3'],
            ],
            'configurations.update' => [
                'id' => ['required', 'integer', 'min:1'],
                'fk_site' => ['required', 'integer', 'min:1'],
                'name' => ['required', 'string', 'min:3'],
                'type' => ['required', 'string', 'min:3'],
            ],
            'configurations.destroy' => [
                'id' => ['required', 'integer', 'min:1'],
                'fk_site' => ['required', 'integer', 'min:1'],
                'fk_office' => ['required', 'integer', 'min:1'],
            ],
            'configurations.changeStatus' => [
                'id' => ['required', 'integer', 'min:1'],
                'fk_site' => ['required', 'integer', 'min:1'],
                'available' => ['required', 'boolean'],
            ],
            'configurations.changeVisibleStatus' => [
                'id' => ['required', 'integer', 'min:1'],
                'fk_site' => ['required', 'integer', 'min:1'],
                'visible' => ['required', 'boolean'],
            ],
            'configurations.show' => [
                'fk_site' => ['required', 'integer', 'min:1'],
                'name' => ['required', 'string', 'min:3'],
            ]
        ];

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