<?php

namespace App\Domains\Purchase\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class PaymentIntentRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() !== null;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'method' => ['required', 'string', Rule::in(['qr', 'transfer'])],
            'transfer_payer_dni' => [
                Rule::requiredIf(fn (): bool => $this->input('method') === 'transfer'),
                'string',
                'regex:/^\d{7,8}$/',
            ],
        ];
    }
}
