<?php

namespace App\Http\Requests\Loan;

use Illuminate\Foundation\Http\FormRequest;

class LoanStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'user_id' => ['required', 'integer', 'exists:users,id'],
            'loan_date' => ['required', 'date', 'date_format:Y-m-d'],
            'amount' => ['required', 'numeric', 'min:0', 'max:999999999999.99'],
            'purpose' => ['nullable', 'string', 'max:1000'],
            'withdrawal_id' => ['nullable', 'integer', 'exists:withdrawals,id'],
        ];
    }

    /**
     * Get the validation attribute names.
     *
     * @return array<string, string>
     */
    public function attributes(): array
    {
        return [
            'user_id' => __('validation.attributes.user_id'),
            'loan_date' => __('validation.attributes.loan_date'),
            'amount' => __('validation.attributes.amount'),
            'purpose' => __('validation.attributes.purpose'),
            'withdrawal_id' => __('validation.attributes.withdrawal_id'),
        ];
    }
}
