<?php

namespace App\Http\Resources;

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

class Cobro extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            "idCobro"           => strval($this->idCobro),
            "numCobro"          => substr(strval($this->idCobro), -12),
            "dateCobro"         => date("Y-m-d H:i:s",strtotime($this->dateCobro)),
            "dateCobroLite"     => date("d-m-y",strtotime($this->dateCobro)),
            "origenCobro"       => $this->origenCobro,
            "nameOrigenCobro"   => $this->nameOrigenCobro,
            "typeCobro"         => $this->typeCobro,
            "nameTypeCobro"     => $this->nameTypeCobro,
            "idEUser"           => strval($this->idEUser),
            "nameEUser"         => $this->nameEUser,
            "idCobrosLista"     => strval($this->idCobrosLista),
            "errorCobro"        => $this->errorCobro,
            "estadoCobro"       => $this->estadoCobro,

            "entidades"         => $this->entidades,
            "entidadFirst"      => $this->entidades->first(),

            "sum_tdt_VES"       => number_format($this->sum_tdt_VES, 2, ',', '.'),
            "sum_tdt_USD"       => number_format($this->sum_tdt_USD, 2, ',', '.'),
            "sum_montoCFP"      => number_format($this->sum_montoCFP, 2, ',', '.'),

            "CFP"               => CobroFormaPago::collection($this->CFP),
            "tdtCobros"         => TransDTCobro::collection($this->tdtCobros),
            "cobrotDTCFP"       => CobroTdtCFP::collection($this->cobrotDTCFP),

        ];
    }
}
