<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'repayment_id' => 'required|exists:loan_repayments,id',
            'phone_number' => 'required|string|regex:/^[0-9]{10,15}$/',
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'repayment_id.required' => 'Repayment ID is required.',
            'repayment_id.exists' => 'The selected repayment is invalid.',
            'phone_number.required' => 'Phone number is required.',
            'phone_number.regex' => 'Please enter a valid phone number (10-15 digits).',
        ];
    }
}
