<?php

namespace App\Http\Requests;

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

class UserGroupRequest 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 = [
            'usergroup.update' => [
                'fk_user' => ['required', 'integer', 'exists:sc_users,id'],
                'groups' => ['required', 'array'],
                'groups.*.fk_group' => ['required', 'integer', 'exists:sy_groups,id'],
                'groups.*.status' => ['required', 'boolean']
            ],
        ];

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