<?php

namespace App\Domains\Client\Resources;

use App\Domains\Client\Models\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/** @mixin Client */
class ClientResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'code' => $this->code,
            'name' => $this->name,
            'tenants' => $this->whenLoaded('tenants', fn () => $this->tenants->map(fn ($tenant): array => [
                'id' => $tenant->id,
                'codigo' => $tenant->codigo,
                'nombre' => $tenant->nombre,
                'dominio' => $tenant->dominio,
            ])),
        ];
    }
}
