<?php

namespace App\Http\Requests\Tenant;

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

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

    /**
     * @return array<string, ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        $tenantId = $this->route('tenant')?->id;

        return [
            'tenant_code' => [
                'sometimes',
                'required',
                'string',
                'max:100',
                Rule::unique('tenants', 'tenant_code')->ignore($tenantId),
            ],
            'tenant_name' => [
                'sometimes',
                'required',
                'string',
                'max:255',
            ],
            'phone' => [
                'nullable',
                'string',
                'max:50',
            ],
            'email' => [
                'nullable',
                'email',
                'max:255',
            ],
            'address' => [
                'nullable',
                'string',
            ],
            'status' => [
                'sometimes',
                'required',
                'in:active,inactive',
            ],
        ];
    }
}
