<?php

namespace App\Http\Requests;

use App\Services\ClinicSettings;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

    public function rules(): array
    {
        $methods = $this->user()
            ? app(ClinicSettings::class)->paymentMethods($this->user()->organization_id)
            : ['cash', 'card', 'bank_transfer', 'online', 'insurance'];

        return [
            'amount' => ['required', 'numeric', 'min:0.01'],
            'method' => ['required', 'string', 'max:60', Rule::in($methods)],
            'reference' => ['nullable', 'string', 'max:190'],
            'provider_reference' => ['nullable', 'string', 'max:190', 'required_without:idempotency_key'],
            'idempotency_key' => ['nullable', 'string', 'max:120', 'required_without:provider_reference'],
            'reason' => ['nullable', 'string', 'max:500'],
            'metadata' => ['nullable', 'array'],
        ];
    }
}
