<?php

namespace App\Http\Requests\Frontend;

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

class StoreWithdrawRequest extends FormRequest
{
    public function authorize(): bool
    {
        return auth()->check();
    }

    protected function prepareForValidation(): void
    {
        $this->merge([
            'mobilenumber' => preg_replace('/\D+/', '', (string) $this->input('mobilenumber')),
            'withdrawamunt' => preg_replace('/\D+/', '', (string) $this->input('withdrawamunt')),
        ]);
    }

    public function rules(): array
    {
        return [
            'paymentwallets' => ['required', Rule::in(['Paytm', 'PhonePe', 'Google Pay'])],
            'mobilenumber' => ['required', 'regex:/^[6-9][0-9]{9}$/'],
            'withdrawamunt' => ['required', 'integer', 'min:1', 'max:99999'],
        ];
    }
}
