<?php

declare(strict_types=1);

namespace App\Http\Requests\Admin;

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

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

    /** @return array<string, array<int, mixed>> */
    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:255'],
            'country_code' => ['required', 'string', 'size:2', 'alpha'],
            'region_code' => ['nullable', 'string', 'max:10'],
            'rate' => ['required', 'numeric', 'min:0', 'max:100'],
            'type' => ['required', Rule::in(['inclusive', 'exclusive'])],
            'priority' => ['integer', 'min:0', 'max:999'],
            'is_active' => ['boolean'],
        ];
    }

    /** @return array<string, string> */
    public function messages(): array
    {
        return [
            'name.required' => 'Tax rate name is required.',
            'country_code.required' => 'Country code is required.',
            'country_code.size' => 'Country code must be exactly 2 characters.',
            'country_code.alpha' => 'Country code must contain only letters.',
            'rate.required' => 'Tax rate percentage is required.',
            'rate.min' => 'Tax rate must be at least 0.',
            'rate.max' => 'Tax rate cannot exceed 100%.',
            'type.required' => 'Tax type is required.',
            'type.in' => 'Tax type must be inclusive or exclusive.',
        ];
    }
}
