<?php
namespace Incoviba\Model;

use Incoviba\Common\Ideal\Model;

class Direccion extends Model
{
    public string $calle;
    public int $numero;
    public string $extra;
    public Comuna $comuna;

    public function full(): string
    {
        return implode(', ', [
            "{$this}",
            $this->comuna->provincia
        ]);
    }

    public function jsonSerialize(): mixed
    {
        return array_merge(parent::jsonSerialize(), [
            'calle' => $this->calle,
            'numero' => $this->numero,
            'extra' => $this->extra,
            'comuna' => $this->comuna
        ]);
    }
    public function __toString(): string
    {
        $array = [
            implode(' ', [
                $this->calle,
                $this->numero
            ])
        ];
        if ($this->extra !== '') {
            $array[]= $this->extra;
        }
        $array []= $this->comuna;
        return implode(', ', $array);
    }
}
