<?php

namespace App\Http\Requests;

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

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

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

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

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