<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;

class WithdrawRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return auth('client')->check();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'withdraw_method_id' => 'required|exists:withdraw_methods,id',
            'coins' => 'required|numeric:gt:0',
            'fields' => 'nullable|array',
            'fields.*.label' => 'required',
            'fields.*.value' => 'required',
        ];
    }

    public function messages(): array
    {

        return [
            'withdraw_method_id.exists' => __('Withdraw method is not active'),
            'withdraw_method_id.required' => __('Withdraw method is required'),
            'amount.gt' => __('The amount must be greater than :min', ['min' => $this->min]),
            'fields.*.value.required' => __('The field is required'),
        ];
    }
}
