<?php

namespace App\Domains\Client\Requests;

use App\Domains\Client\Models\Client;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateClientRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        /** @var Client|null $client */
        $client = $this->route('client');

        return [
            'code' => ['sometimes', 'string', 'max:255', Rule::unique('clients', 'code')->ignore($client?->id)],
            'name' => ['sometimes', 'string', 'max:255'],
        ];
    }
}
