<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class UserResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'role' => $this->role,
            'nome' => $this->nome,
            'telefone' => $this->telefone,
            'email' => $this->email,
            'endereco' => $this->endereco,
            'fotoUri' => $this->foto_uri,
            'verified' => ! is_null($this->email_verified_at),

            $this->mergeWhen($this->role === 'entregador', [
                'bi' => $this->bi,
                'cartaConducao' => $this->carta_conducao,
                'tipoVeiculo' => $this->tipo_veiculo,
                'seguro' => $this->seguro,
            ]),

            $this->mergeWhen($this->role === 'parceiro', [
                'nomeLoja' => $this->nome_loja,
                'categoria' => $this->categoria,
                'nuit' => $this->nuit,
            ]),
        ];
    }
}
