<?php

namespace App\Http\Requests;

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

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

    /**
     * @return array<string, array<int, mixed>>
     */
    public function rules(): array
    {
        /** @var MoraqebatMachine|null $machine */
        $machine = $this->route('moraqebatMachine');

        return [
            'name' => [
                'required',
                'string',
                'max:255',
                Rule::unique(MoraqebatMachine::class, 'name')->ignore($machine?->id),
            ],
        ];
    }
}
