<?php
namespace Incoviba\Model\Contabilidad;

use DateTimeInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model\Contabilidad\Movimiento\Detalle;
use Incoviba\Model\Inmobiliaria;

class Movimiento extends Ideal\Model
{
    public Inmobiliaria\Cuenta $cuenta;
    public DateTimeInterface $fecha;
    public string $glosa;
    public string $documento;
    public int $cargo;
    public int $abono;
    public int $saldo;

    protected ?Detalle $detalles;
    public function getDetalles(): ?Detalle
    {
        if (!isset($this->detalles)) {
            $this->detalles = $this->runFactory('detalles');
        }
        return $this->detalles;
    }

    /*protected ?array $auxiliares;
    public function getAuxiliares(): ?array
    {
        if (!isset($this->auxiliares)) {
            $this->auxiliares = $this->runFactory('auxiliares');
        }
        return $this->auxiliares;
    }*/

    public function jsonSerialize(): mixed
    {
        return array_merge(parent::jsonSerialize(), [
            'cuenta_id' => $this->cuenta->id,
            'fecha' => $this->fecha->format('Y-m-d'),
            'glosa' => $this->glosa,
            'documento' => $this->documento,
            'cargo' => $this->cargo,
            'abono' => $this->abono,
            'saldo' => $this->saldo,
            'detalles' => $this->getDetalles(),
            //'auxiliares' => $this->getAuxiliares()
        ]);
    }
}
