<?php
/* This file has been auto-generated. Do not edit this file directly. */
namespace SabaiApps\Directories\Component\System\Model\Base;

use SabaiApps\Framework\Model\Model;
use SabaiApps\Framework\Criteria\AbstractCriteria;
use SabaiApps\Framework\DB\AbstractRowset;
use SabaiApps\Framework\Model\AbstractEntity;
use SabaiApps\Framework\Model\AbstractEntityRepository;

abstract class Component extends AbstractEntity
{
    public function __construct(Model $model)
    {
        parent::__construct('Component', $model);
        $this->_vars = ['id' => null, 'component_name' => null, 'component_version' => null, 'component_priority' => 0, 'component_config' => null, 'component_events' => null, 'component_created' => 0, 'component_updated' => 0];
    }

    public function __clone()
    {
        $this->_vars = ['id' => null, 'component_name' => null, 'component_created' => 0, 'component_updated' => 0] + $this->_vars;
    }

    public function __toString()
    {
        return $this->__get('name');
    }

    public function initVars(array $arr)
    {
        parent::initVars($arr);
        $this->_vars['id'] = $this->_vars['component_name'];
    }

    public function __get($name)
    {
        if ($name === 'id')
            return $this->_vars['id'];
        elseif ($name === 'name')
            return $this->_vars['component_name'];
        elseif ($name === 'version')
            return $this->_vars['component_version'];
        elseif ($name === 'priority')
            return $this->_vars['component_priority'];
        elseif ($name === 'config')
            return $this->_vars['component_config'];
        elseif ($name === 'events')
            return $this->_vars['component_events'];
        elseif ($name === 'created')
            return $this->_vars['component_created'];
        elseif ($name === 'updated')
            return $this->_vars['component_updated'];
        else
            return $this->fetchObject($name);
    }

    public function __set($name, $value)
    {
        if ($name === 'id')
            $this->_setVar('id', $value);
        elseif ($name === 'name')
            $this->_setVar('component_name', $value);
        elseif ($name === 'version')
            $this->_setVar('component_version', $value);
        elseif ($name === 'priority')
            $this->_setVar('component_priority', $value);
        elseif ($name === 'config')
            $this->_setVar('component_config', $value);
        elseif ($name === 'events')
            $this->_setVar('component_events', $value);
        else
            $this->assignObject($name, $value);
    }

    protected function _initVar($name, $value)
    {
        if ($name === 'component_priority')
            $this->_vars['component_priority'] = (int)$value;
        elseif ($name === 'component_config')
            $this->_vars['component_config'] = @unserialize($value);
        elseif ($name === 'component_events')
            $this->_vars['component_events'] = @unserialize($value);
        elseif ($name === 'component_created')
            $this->_vars['component_created'] = (int)$value;
        elseif ($name === 'component_updated')
            $this->_vars['component_updated'] = (int)$value;
        else
            $this->_vars[$name] = $value;
    }
}

abstract class ComponentRepository extends AbstractEntityRepository
{
    public function __construct(Model $model)
    {
        parent::__construct('Component', $model);
    }

    protected function _getCollectionByRowset(AbstractRowset $rs)
    {
        return new ComponentsByRowset($rs, $this->_model->create('Component'), $this->_model);
    }

    public function createCollection(array $entities = [])
    {
        return new Components($this->_model, $entities);
    }
}

class ComponentsByRowset extends \SabaiApps\Framework\Model\EntityCollection\RowsetEntityCollection
{
    public function __construct(AbstractRowset $rs, Component $emptyEntity, Model $model)
    {
        parent::__construct('Components', $rs, $emptyEntity, $model);
    }
}

class Components extends \SabaiApps\Framework\Model\EntityCollection\ArrayEntityCollection
{
    public function __construct(Model $model, array $entities = [])
    {
        parent::__construct($model, 'Components', $entities);
    }
}