<?php
namespace Incoviba\Common\Ideal;

use Incoviba\Common\Define;

abstract class Model implements Define\Model
{
    public int $id;

    protected array $factories;

    public function addFactory(string $property, Define\Repository\Factory $factory): Model
    {
        $this->factories[$property] = $factory;
        return $this;
    }

    protected function runFactory(string $property): mixed
    {
        if (isset($this->factories[$property])) {
            return $this->factories[$property]->run();
        }
        return null;
    }

    public function jsonSerialize(): mixed
    {
        return [
            'id' => $this->id
        ];
    }
}
