<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class LoanSuperManagerApprovalRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return auth()->user()->hasRole('Super Manager') && auth()->user()->can('approve loan applications');
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'approved_amount' => 'nullable|numeric|min:0',
            'notes' => 'nullable|string|max:1000',
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'approved_amount.numeric' => 'Approved amount must be a number.',
            'approved_amount.min' => 'Approved amount must be greater than or equal to 0.',
            'notes.max' => 'Notes must not exceed 1000 characters.',
        ];
    }
}
