<?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 Feature extends AbstractEntity
{
    public function __construct(Model $model)
    {
        parent::__construct('Feature', $model);
        $this->_vars = ['feature_status' => 0, 'feature_feature_name' => null, 'feature_metas' => null, 'feature_logs' => null, 'feature_id' => 0, 'feature_created' => 0, 'feature_updated' => 0, 'feature_featuregroup_id' => 0];
    }

    public function __clone()
    {
        $this->_vars = ['feature_id' => 0, 'feature_created' => 0, 'feature_updated' => 0] + $this->_vars;
    }

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

    public function __get($name)
    {
        if ($name === 'status')
            return $this->_vars['feature_status'];
        elseif ($name === 'feature_name')
            return $this->_vars['feature_feature_name'];
        elseif ($name === 'metas')
            return $this->_vars['feature_metas'];
        elseif ($name === 'logs')
            return $this->_vars['feature_logs'];
        elseif ($name === 'id')
            return $this->_vars['feature_id'];
        elseif ($name === 'created')
            return $this->_vars['feature_created'];
        elseif ($name === 'updated')
            return $this->_vars['feature_updated'];
        elseif ($name === 'featuregroup_id')
            return $this->_vars['feature_featuregroup_id'];
        elseif ($name === 'FeatureGroup')
            return $this->_fetchEntity('FeatureGroup', 'featuregroup_id');
        else
            return $this->fetchObject($name);
    }

    public function __set($name, $value)
    {
        if ($name === 'status')
            $this->_setVar('feature_status', $value);
        elseif ($name === 'feature_name')
            $this->_setVar('feature_feature_name', $value);
        elseif ($name === 'metas')
            $this->_setVar('feature_metas', $value);
        elseif ($name === 'logs')
            $this->_setVar('feature_logs', $value);
        elseif ($name === 'id')
            $this->_setVar('feature_id', $value);
        elseif ($name === 'featuregroup_id')
            $this->_assignEntityById('FeatureGroup', $value, 'feature_featuregroup_id');
        elseif ($name === 'FeatureGroup') {
            $_value = is_array($value) ? $value[0] : $value;
            if (is_object($_value)) {
                $this->_assignEntity($_value, 'feature_featuregroup_id');
            } else {
                $this->_assignEntityById('FeatureGroup', $_value, 'feature_featuregroup_id');
            }
        }
        else
            $this->assignObject($name, $value);
    }

    protected function _initVar($name, $value)
    {
        if ($name === 'feature_status')
            $this->_vars['feature_status'] = (int)$value;
        elseif ($name === 'feature_metas')
            $this->_vars['feature_metas'] = @unserialize($value);
        elseif ($name === 'feature_logs')
            $this->_vars['feature_logs'] = @unserialize($value);
        elseif ($name === 'feature_id')
            $this->_vars['feature_id'] = (int)$value;
        elseif ($name === 'feature_created')
            $this->_vars['feature_created'] = (int)$value;
        elseif ($name === 'feature_updated')
            $this->_vars['feature_updated'] = (int)$value;
        elseif ($name === 'feature_featuregroup_id')
            $this->_vars['feature_featuregroup_id'] = (int)$value;
        else
            $this->_vars[$name] = $value;
    }
}

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

    public function fetchByFeatureGroup($id, $limit = 0, $offset = 0, $sort = null, $order = null)
    {
        return $this->_fetchByForeign('feature_featuregroup_id', $id, $limit, $offset, $sort, $order);
    }

    public function paginateByFeatureGroup($id, $perpage = 10, $sort = null, $order = null)
    {
        return $this->_paginateByEntity('FeatureGroup', $id, $perpage, $sort, $order);
    }

    public function countByFeatureGroup($id)
    {
        return $this->_countByForeign('feature_featuregroup_id', $id);
    }

    public function fetchByFeatureGroupAndCriteria($id, AbstractCriteria $criteria, $limit = 0, $offset = 0, $sort = null, $order = null)
    {
        return $this->_fetchByForeignAndCriteria('feature_featuregroup_id', $id, $criteria, $limit, $offset, $sort, $order);
    }

    public function paginateByFeatureGroupAndCriteria($id, AbstractCriteria $criteria, $perpage = 10, $sort = null, $order = null)
    {
        return $this->_paginateByEntityAndCriteria('FeatureGroup', $id, $criteria, $perpage, $sort, $order);
    }

    public function countByFeatureGroupAndCriteria($id, AbstractCriteria $criteria)
    {
        return $this->_countByForeignAndCriteria('feature_featuregroup_id', $id, $criteria);
    }

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

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

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

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