<?php

namespace App\Modules\Platform\Geography\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateTenantCityRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('geography.manage') ?? false;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'region_id' => ['required', 'integer', 'exists:geo_regions,id'],
            'name_en' => ['required', 'string', 'max:120'],
            'name_ar' => ['nullable', 'string', 'max:120'],
            'sort_order' => ['nullable', 'integer', 'min:0', 'max:65535'],
            'is_active' => ['required', 'boolean'],
        ];
    }

    protected function prepareForValidation(): void
    {
        if ($this->has('is_active')) {
            $this->merge(['is_active' => (bool) $this->input('is_active')]);
        }
    }
}
