<?php

declare(strict_types=1);

namespace App\Http\Requests;

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

class UpdateRegionRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('update', $this->route('region'));
    }

    public function rules(): array
    {
        $regionId = $this->route('region')->id;

        return [
            'name' => ['required', 'string', 'max:120', Rule::unique('regions', 'name')->ignore($regionId)],
            'code' => ['required', 'string', 'max:20', Rule::unique('regions', 'code')->ignore($regionId)],
            'is_active' => ['sometimes', 'boolean'],
        ];
    }
}
