<?php

namespace App\Http\Requests;

use App\Models\Saraf;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateSarafRequest extends FormRequest
{
    public function authorize(): bool
    {
        return (bool) $this->user()?->can('sarafs.update');
    }

    /**
     * @return array<string, array<int, mixed>>
     */
    public function rules(): array
    {
        /** @var Saraf $saraf */
        $saraf = $this->route('saraf');

        return [
            'name' => [
                'required',
                'string',
                'max:255',
                Rule::unique(Saraf::class, 'name')->ignore($saraf->id),
            ],
            'address' => ['nullable', 'string', 'max:1000'],
            'contact_number' => ['nullable', 'string', 'max:30'],
        ];
    }
}
