<?php

namespace App\Http\Requests;

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

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

    public function rules(): array
    {
        $route = Route::getCurrentRoute()->getName();
        $rules = [
            'fk_site' => ['required', 'integer', 'exists:sy_sites,id'],
            'fk_office' => ['required', 'integer', 'exists:sy_offices,id']
        ];

        $routeRules = [
            'zone.index' => [],
            'zone.store' => [
                'fk_city' => ['sometimes', 'nullable', 'integer', 'exists:ct_cities,id'],
                'zonename' => ['required', 'string', 'min:2', 'max:50'],
                'fk_executive' => ['sometimes', 'nullable', 'integer', 'exists:ct_collaborators,id']
            ],
            'zone.update' => [
                'id' => ['required', 'integer', 'exists:sy_zones,id'],
                'fk_city' => ['sometimes', 'nullable', 'integer', 'exists:ct_cities,id'],
                'zonename' => ['required', 'string', 'min:2', 'max:50'],
                'fk_executive' => ['sometimes', 'nullable', 'integer', 'exists:ct_collaborators,id']
            ],
            'zone.destroy' => [
                'id' => ['required', 'integer', 'exists:sy_zones,id'],
            ],
            'zone.changeStatus' => [
                'id' => ['required', 'integer', 'exists:sy_zones,id'],
                'available' => ['required', 'boolean']
            ],
            'zone.changeVisibility' => [
                'id' => ['required', 'integer', 'exists:sy_zones,id'],
                'visible' => ['required', 'boolean']
            ],
            'zone.list' => [],
            'zone.show' => [
                'id' => ['required', 'integer', 'exists:sy_zones,id'],
            ],
        ];

        return array_merge($rules, $routeRules[$route]);
    }
}
