<?php

namespace App\Http\Requests\Hr;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreLoanRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->hasPermission('payroll.process') === true;
    }

    public function rules(): array
    {
        return [
            'type' => ['required', Rule::in(['loan', 'salary_advance'])],
            'amount' => ['required', 'numeric', 'min:0.01'],
            'loan_date' => ['required', 'date'],
            'installment_amount' => ['required', 'numeric', 'min:0.01', 'lte:amount'],
            'start_month' => ['required', 'date'],
            'notes' => ['nullable', 'string', 'max:2000'],
        ];
    }
}
