<?php

namespace App\Http\Requests\Unit;

use Illuminate\Foundation\Http\FormRequest;

class UpdateUnitRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->isAdmin();
    }

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

        return [
            'unit_name' => ['sometimes', 'string', 'max:100'],
            'unit_code' => ['sometimes', 'string', 'max:100', "unique:units,unit_code,{$unitId}"],
            'location'  => ['nullable', 'string', 'max:255'],
            'status'    => ['sometimes', 'in:active,inactive'],
            'notes'     => ['nullable', 'string'],
        ];
    }
}
