<?php

namespace App\Http\Requests;

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

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

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

        $routeRules = [
            'status.index' => [],
            'status.store' => [
                'fk_status_type' => ['required', 'integer', 'exists:ct_status_types,id'],
                'statusname' => ['required', 'string', 'min:2', 'max:35'],
                'classname' => ['string', 'min:2', 'max:20'],
            ],
            'status.update' => [
                'id' => ['required', 'integer', 'exists:sy_statuses,id'],
                'fk_status_type' => ['required', 'integer', 'exists:ct_status_types,id'],
                'statusname' => ['required', 'string', 'min:2', 'max:35'],
                'classname' => ['string', 'min:2', 'max:20'],
            ],
            'status.destroy' => [
                'id' => ['required', 'integer', 'exists:sy_statuses,id'],
            ],
            'status.changeStatus' => [
                'id' => ['required', 'integer', 'exists:sy_statuses,id'],
                'available' => ['required', 'boolean'],
            ],
            'status.changeVisibility' => [
                'id' => ['required', 'integer', 'exists:sy_statuses,id'],
                'visible' => ['required', 'boolean'],
            ],
            'status.list' => [
                'status_type' => ['sometimes', 'string', 'min:5']
            ],
        ];

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