<?php
/* This file has been auto-generated. Do not edit this file directly. */
namespace SabaiApps\Directories\Component\Entity\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 FieldConfig extends AbstractEntity {

	public function __construct( Model $model ) {
		parent::__construct( 'FieldConfig', $model );
		$this->_vars = array(
			'id'                          => null,
			'fieldconfig_name'            => null,
			'fieldconfig_type'            => null,
			'fieldconfig_system'          => 0,
			'fieldconfig_settings'        => null,
			'fieldconfig_property'        => null,
			'fieldconfig_schema'          => null,
			'fieldconfig_schema_type'     => null,
			'fieldconfig_entitytype_name' => null,
			'fieldconfig_bundle_type'     => null,
			'fieldconfig_created'         => 0,
			'fieldconfig_updated'         => 0,
		);
	}

	public function __clone() {
		$this->_vars = array(
			'id'                  => null,
			'fieldconfig_name'    => null,
			'fieldconfig_created' => 0,
			'fieldconfig_updated' => 0,
		) + $this->_vars;
	}

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

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

	public function addField( Field $entity ) {
		$entity->FieldConfig = $this;

		return $this;
	}

	public function removeField( Field $entity ) {
		$this->removeFieldById( $entity->id );

		return $this;
	}

	public function removeFieldById( $id ) {
		$this->_removeEntityById( 'field_id', 'Field', $id );

		return $this;
	}

	public function createField() {
		return $this->_createEntity( 'Field' );
	}

	public function removeFields() {
		$this->_removeEntities( 'Field' );

		return $this;
	}

	public function __get( $name ) {
		if ( $name === 'id' ) {
			return $this->_vars['id'];
		} elseif ( $name === 'name' ) {
			return $this->_vars['fieldconfig_name'];
		} elseif ( $name === 'type' ) {
			return $this->_vars['fieldconfig_type'];
		} elseif ( $name === 'system' ) {
			return $this->_vars['fieldconfig_system'];
		} elseif ( $name === 'settings' ) {
			return $this->_vars['fieldconfig_settings'];
		} elseif ( $name === 'property' ) {
			return $this->_vars['fieldconfig_property'];
		} elseif ( $name === 'schema' ) {
			return $this->_vars['fieldconfig_schema'];
		} elseif ( $name === 'schema_type' ) {
			return $this->_vars['fieldconfig_schema_type'];
		} elseif ( $name === 'entitytype_name' ) {
			return $this->_vars['fieldconfig_entitytype_name'];
		} elseif ( $name === 'bundle_type' ) {
			return $this->_vars['fieldconfig_bundle_type'];
		} elseif ( $name === 'created' ) {
			return $this->_vars['fieldconfig_created'];
		} elseif ( $name === 'updated' ) {
			return $this->_vars['fieldconfig_updated'];
		} elseif ( $name === 'Fields' ) {
			return $this->_fetchEntities( 'Field', 'Fields' );
		} else {
			return $this->fetchObject( $name );
		}
	}

	public function __set( $name, $value ) {
		if ( $name === 'id' ) {
			$this->_setVar( 'id', $value );
		} elseif ( $name === 'name' ) {
			$this->_setVar( 'fieldconfig_name', $value );
		} elseif ( $name === 'type' ) {
			$this->_setVar( 'fieldconfig_type', $value );
		} elseif ( $name === 'system' ) {
			$this->_setVar( 'fieldconfig_system', $value );
		} elseif ( $name === 'settings' ) {
			$this->_setVar( 'fieldconfig_settings', $value );
		} elseif ( $name === 'property' ) {
			$this->_setVar( 'fieldconfig_property', $value );
		} elseif ( $name === 'schema' ) {
			$this->_setVar( 'fieldconfig_schema', $value );
		} elseif ( $name === 'schema_type' ) {
			$this->_setVar( 'fieldconfig_schema_type', $value );
		} elseif ( $name === 'entitytype_name' ) {
			$this->_setVar( 'fieldconfig_entitytype_name', $value );
		} elseif ( $name === 'bundle_type' ) {
			$this->_setVar( 'fieldconfig_bundle_type', $value );
		} elseif ( $name === 'Fields' ) {
			$this->removeFields();
			foreach ( array_keys( $value ) as $i ) {
				$this->addField( $value[ $i ] );
			}
		} else {
			$this->assignObject( $name, $value );
		}
	}

	protected function _initVar( $name, $value ) {
		if ( $name === 'fieldconfig_system' ) {
			$this->_vars['fieldconfig_system'] = (int) $value;
		} elseif ( $name === 'fieldconfig_settings' ) {
			$this->_vars['fieldconfig_settings'] = @unserialize( $value );
		} elseif ( $name === 'fieldconfig_schema' ) {
			$this->_vars['fieldconfig_schema'] = @unserialize( $value );
		} elseif ( $name === 'fieldconfig_created' ) {
			$this->_vars['fieldconfig_created'] = (int) $value;
		} elseif ( $name === 'fieldconfig_updated' ) {
			$this->_vars['fieldconfig_updated'] = (int) $value;
		} else {
			$this->_vars[ $name ] = $value;
		}
	}
}

abstract class FieldConfigRepository extends AbstractEntityRepository {

	public function __construct( Model $model ) {
		parent::__construct( 'FieldConfig', $model );
	}

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

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

class FieldConfigsByRowset extends \SabaiApps\Framework\Model\EntityCollection\RowsetEntityCollection {

	public function __construct( AbstractRowset $rs, FieldConfig $emptyEntity, Model $model ) {
		parent::__construct( 'FieldConfigs', $rs, $emptyEntity, $model );
	}
}

class FieldConfigs extends \SabaiApps\Framework\Model\EntityCollection\ArrayEntityCollection {

	public function __construct( Model $model, array $entities = array() ) {
		parent::__construct( $model, 'FieldConfigs', $entities );
	}
}
