<?php

declare(strict_types=1);

namespace App\Http\Requests\Settings;

use App\Http\Requests\UsernameRequest;
use Illuminate\Foundation\Http\FormRequest;

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

    protected function prepareForValidation(): void
    {
        if ($this->has('username')) {
            $this->merge([
                'username' => \App\Support\UsernamePolicy::normalize((string) $this->input('username')),
            ]);
        }
    }

    public function rules(): array
    {
        return [
            'username' => ['required', ...UsernameRequest::rulesFor((int) $this->user()->id)],
        ];
    }
}
