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

use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Model;

class Detalle extends Ideal\Model
{
    public Model\Contabilidad\Movimiento $movimiento;
    public ?Model\Contabilidad\CentroCosto $centroCosto;
    public ?int $rut;
    public ?string $digito;
    public ?string $nombres;
    public ?string $categoria;
    public ?string $detalle;
    public ?string $identificador;

    public function rut(): string
    {
        return $this->rut . '-' . $this->digito;
    }
    public function rutFormatted(): string
    {
        return number_format($this->rut, 0, ',', '.') . '-' . $this->digito;
    }

    public ?Define\Model $relacionado;
    public ?string $relacionadoType;

    public function jsonSerialize(): mixed
    {
        return [
            'movimiento_id' => $this->movimiento->id,
            'centro_costo' => $this->centroCosto,
            'rut' => $this->rut,
            'digito' => $this->digito,
            'nombres' => $this->nombres,
            'categoria' => $this->categoria,
            'detalle' => $this->detalle,
            'identificador' => $this->identificador,
            'rutFormatted' => $this->rutFormatted(),
            'relacionado' => $this->relacionado ?? null,
            'relacionadoType' => $this->relacionadoType ?? null
        ];
    }
}
