<?php

namespace App\Http\Requests\Player;

use App\Http\Requests\Admin\Concerns\AdminAccountFieldRules;
use App\Http\Requests\ApiFormRequest;

final class PlayerAuthLoginRequest extends ApiFormRequest
{
    use AdminAccountFieldRules;

    public function authorize(): bool
    {
        return true;
    }

    protected function prepareForValidation(): void
    {
        $this->normalizeAdminAccountFields();
        if ($this->has('username')) {
            $this->merge(['username' => strtolower(trim((string) $this->input('username')))]);
        }
    }

    public function rules(): array
    {
        return [
            'site_code' => ['sometimes', 'nullable', 'string', 'max:64'],
            'username' => $this->nativePlayerUsernameRules(required: true),
            'password' => $this->nativePlayerPasswordRules(required: true),
            'captcha_key' => ['required', 'string', 'uuid'],
            'captcha_code' => ['required', 'string', 'max:32'],
        ];
    }
}
