<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ExchangeRateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'base_currency' => ['required', 'string', 'size:3'],
            'rates' => ['required', 'array'],
            'rates.*' => ['required', 'numeric', 'min:0'],
            'updated_by' => ['required', 'string', 'max:255'],
        ];
    }

    public function messages(): array
    {
        return [
            'base_currency.required' => 'Base currency is required.',
            'base_currency.size' => 'Base currency must be a 3-letter code (e.g. USD).',

            'rates.required' => 'Exchange rates are required.',
            'rates.array' => 'Rates must be a valid key-value structure.',

            'rates.*.numeric' => 'Each rate must be a number.',
            'rates.*.min' => 'Rates cannot be negative.',
        ];
    }
}
