<?php

namespace App\Http\Requests\Admin\Country;

use Illuminate\Foundation\Http\FormRequest;

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

    protected function prepareForValidation(): void
    {
        $this->merge([
            'is_active' => $this->boolean('is_active', true),
        ]);
    }

    public function rules(): array
    {
        return [
            'code'       => ['required', 'string', 'max:3', 'unique:countries,code'],
            'name'       => ['required', 'array'],
            'name.en'    => ['required', 'string', 'max:100'],
            'name.ar'    => ['nullable', 'string', 'max:100'],
            'phone_code' => ['nullable', 'string', 'max:10'],
            'is_active'  => ['boolean'],
        ];
    }

    public function attributes(): array
    {
        return [
            'code'       => __('dashboard.code'),
            'name.en'    => __('dashboard.name_en'),
            'name.ar'    => __('dashboard.name_ar'),
            'phone_code' => __('dashboard.phone_code'),
            'is_active'  => __('dashboard.status'),
        ];
    }
}
