<?php
namespace Incoviba\Model\Contabilidad\Movimiento;

use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;

class Auxiliar extends Ideal\Model
{
    public Model\Contabilidad\Movimiento $movimiento;
    public int $cargo;
    public int $abono;

    protected ?Model\Contabilidad\Movimiento\Auxiliar\Detalle $detalles;
    public function getDetalles(): ?Model\Contabilidad\Movimiento\Auxiliar\Detalle
    {
        if (!isset($this->detalles)) {
            try {
                $this->detalles = $this->runFactory('detalles');
            } catch (Implement\Exception\EmptyResult) {
                $this->detalles = null;
            }
        }
        return $this->detalles;
    }

    public function jsonSerialize(): mixed
    {
        return array_merge(parent::jsonSerialize(), [
            'movimiento_id' => $this->movimiento->id,
            'cargo' => $this->cargo,
            'abono' => $this->abono,
            'detalles' => $this->getDetalles()
        ]);
    }
}
