<?php

namespace App\Http\Requests;

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

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

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

        $routeRules = [
            'statustype.index' => [
                'fk_site' => ['required', 'integer', 'exists:sy_sites,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id']
            ],
            'statustype.store' => [
                'fk_site' => ['required', 'integer', 'exists:sy_sites,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
                'statustypename' => ['required', 'string', 'min:2', 'max:30']
            ],
            'statustype.update' => [
                'id' => ['required', 'integer', 'exists:ct_status_types,id'],
                'fk_site' => ['required', 'integer', 'exists:sy_sites,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
                'statustypename' => ['required', 'string', 'min:2', 'max:30']
            ],
            'statustype.destroy' => [
                'id' => ['required', 'integer', 'exists:ct_status_types,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
            ],
            'statustype.changeStatus' => [
                'id' => ['required', 'integer', 'exists:ct_status_types,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
                'available' => ['required', 'boolean']
            ],
            'statustype.changeVisibility' => [
                'id' => ['required', 'integer', 'exists:ct_status_types,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
                'visible' => ['required', 'boolean']
            ],
            'statustype.list' => [
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
            ]
        ];

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