<?php

declare(strict_types=1);

namespace Maestro\Core\Http\Requests\Superadmin;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Maestro\Core\Support\AuthUserResolver;

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

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        $userClass = AuthUserResolver::eloquentModelClass();
        /** @var Model $u */
        $u = new $userClass;
        $usersTable = $u->getTable();

        return [
            'userId' => ['required', 'integer', Rule::exists($usersTable, 'id')],
            'tableKey' => ['required', 'string', 'max:128', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/'],
        ];
    }
}
