<?php

declare(strict_types=1);

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

class StoreCreditNoteRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    /** @return array<string, array<int, mixed>> */
    public function rules(): array
    {
        return [
            'user_id' => ['required', 'exists:users,id'],
            'amount' => ['required', 'numeric', 'min:0.01'],
            'reason' => ['nullable', 'string', 'max:2000'],
            'invoice_id' => ['nullable', 'exists:invoices,id'],
        ];
    }

    /** @return array<string, string> */
    public function messages(): array
    {
        return [
            'user_id.required' => 'Please select a customer.',
            'user_id.exists' => 'The selected customer does not exist.',
            'amount.required' => 'Amount is required.',
            'amount.min' => 'Amount must be at least $0.01.',
            'invoice_id.exists' => 'The selected invoice does not exist.',
        ];
    }
}
