<?php
namespace Incoviba\Model\Proyecto;

use Incoviba\Common;

class Broker extends Common\Ideal\Model
{
    public int $rut;
    public string $digit;
    public string $name;

    protected ?Broker\Data $data;
    public function data(): ?Broker\Data
    {
        if (!isset($this->data)) {
            $this->data = $this->runFactory('data');
        }
        return $this->data;
    }

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

    public function rutFull(): string
    {
        return implode('-', [number_format($this->rut, 0, ',', '.'), $this->digit]);
    }

    public function jsonSerialize(): mixed
    {
        return [
            'rut' => $this->rut,
            'digit' => $this->digit,
            'name' => $this->name,
            'data' => $this->data(),
            'rut_full' => $this->rutFull()
        ];
    }
}
