<?php

namespace App\Http\Resources\Ambiental;

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

class EcopontoResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id'                    => $this->id,
            'nome'                  => $this->nome,
            'descricao'             => $this->descricao,
            'endereco'              => $this->endereco,
            'latitude'              => $this->latitude,
            'longitude'             => $this->longitude,
            'tipos_residuo'         => $this->tipos_residuo,
            'horario_funcionamento' => $this->horario_funcionamento,
            'status'                => $this->status,
            'total_doacoes'         => $this->doacoes_count ?? 0,
            'distancia_km'          => isset($this->distancia_km)
                ? round((float) $this->distancia_km, 2)
                : null,
            'criado_em'             => $this->created_at?->toIso8601String(),
        ];
    }
}
