<?php
/* This file has been auto-generated. Do not edit this file directly. */
namespace SabaiApps\Directories\Component\Payment\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 FeatureGroup extends AbstractEntity
{
    public function __construct(Model $model)
    {
        parent::__construct('FeatureGroup', $model);
        $this->_vars = ['featuregroup_logs' => null, 'featuregroup_bundle_name' => null, 'featuregroup_order_id' => 0, 'featuregroup_id' => 0, 'featuregroup_created' => 0, 'featuregroup_updated' => 0];
    }

    public function __clone()
    {
        $this->_vars = ['featuregroup_id' => 0, 'featuregroup_created' => 0, 'featuregroup_updated' => 0] + $this->_vars;
    }

    public function __toString()
    {
        return 'FeatureGroup:' . $this->__get('id');
    }

    public function addFeature(Feature $entity)
    {
        $entity->FeatureGroup = $this;

        return $this;
    }

    public function removeFeature(Feature $entity)
    {
        $this->removeFeatureById($entity->id);

        return $this;
    }

    public function removeFeatureById($id)
    {
        $this->_removeEntityById('feature_id', 'Feature', $id);

        return $this;
    }

    public function createFeature()
    {
        return $this->_createEntity('Feature');
    }

    public function removeFeatures()
    {
        $this->_removeEntities('Feature');

        return $this;
    }

    public function __get($name)
    {
        if ($name === 'logs')
            return $this->_vars['featuregroup_logs'];
        elseif ($name === 'bundle_name')
            return $this->_vars['featuregroup_bundle_name'];
        elseif ($name === 'order_id')
            return $this->_vars['featuregroup_order_id'];
        elseif ($name === 'id')
            return $this->_vars['featuregroup_id'];
        elseif ($name === 'created')
            return $this->_vars['featuregroup_created'];
        elseif ($name === 'updated')
            return $this->_vars['featuregroup_updated'];
        elseif ($name === 'Features')
            return $this->_fetchEntities('Feature', 'Features');
        else
            return $this->fetchObject($name);
    }

    public function __set($name, $value)
    {
        if ($name === 'logs')
            $this->_setVar('featuregroup_logs', $value);
        elseif ($name === 'bundle_name')
            $this->_setVar('featuregroup_bundle_name', $value);
        elseif ($name === 'order_id')
            $this->_setVar('featuregroup_order_id', $value);
        elseif ($name === 'id')
            $this->_setVar('featuregroup_id', $value);
        elseif ($name === 'Features') {
            $this->removeFeatures();
            foreach (array_keys($value) as $i) $this->addFeature($value[$i]);
        }
        else
            $this->assignObject($name, $value);
    }

    protected function _initVar($name, $value)
    {
        if ($name === 'featuregroup_logs')
            $this->_vars['featuregroup_logs'] = @unserialize($value);
        elseif ($name === 'featuregroup_order_id')
            $this->_vars['featuregroup_order_id'] = (int)$value;
        elseif ($name === 'featuregroup_id')
            $this->_vars['featuregroup_id'] = (int)$value;
        elseif ($name === 'featuregroup_created')
            $this->_vars['featuregroup_created'] = (int)$value;
        elseif ($name === 'featuregroup_updated')
            $this->_vars['featuregroup_updated'] = (int)$value;
        else
            $this->_vars[$name] = $value;
    }
}

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

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

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

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

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