<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateLoanRescheduleRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return auth()->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 [
            'new_amount' => 'nullable|numeric|min:0',
            'new_duration' => 'nullable|integer|min:1',
            'new_interest_rate' => 'nullable|numeric|min:0|max:100',
            'reason' => 'nullable|string|max:1000',
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'new_amount.numeric' => 'New amount must be a valid number.',
            'new_amount.min' => 'New amount cannot be negative.',
            'new_duration.integer' => 'New duration must be a valid number.',
            'new_duration.min' => 'New duration must be at least 1 month.',
            'new_interest_rate.numeric' => 'New interest rate must be a valid number.',
            'new_interest_rate.min' => 'New interest rate cannot be negative.',
            'new_interest_rate.max' => 'New interest rate cannot exceed 100%.',
            'reason.max' => 'Reason cannot exceed 1000 characters.',
        ];
    }
}
