<?php
namespace Incoviba\Model;

use Incoviba\Common\Ideal\Model;
use Incoviba\Model\Inmobiliaria\TipoSociedad;

class Inmobiliaria extends Model
{
    public int $rut;
    public ?string $dv;
    public ?string $razon;
    public ?string $abreviacion;
    public ?TipoSociedad $tipoSociedad;
    public string $sigla;

    public function rut(): string
    {
        return implode('-', [
            number_format($this->rut, 0, ',', '.'),
            $this->dv
        ]);
    }
    public function nombreCompleto(): string
    {
        return implode(' ', [
            $this->razon,
            $this->tipoSociedad->descripcion
        ]);
    }

    public function jsonSerialize(): mixed
    {
        return [
            'rut' => $this->rut,
            'dv' => $this->dv ?? '',
            'rut_formateado' => $this->rut(),
            'razon' => $this->razon ?? '',
            'abreviacion' => $this->abreviacion ?? '',
            'tipo_sociedad' => $this->tipoSociedad ?? '',
            'sigla' => $this->sigla,
        ];
    }
}
