// ------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool Xbim.CodeGeneration 
//  
//     Changes to this file may cause incorrect behaviour and will be lost if
//     the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------

using Xbim.Ifc4x3.MeasureResource;
using Xbim.Ifc4x3.PropertyResource;
using Xbim.Ifc4x3.UtilityResource;
using System;
using System.Collections.Generic;
using System.Linq;
using Xbim.Common;
using Xbim.Common.Exceptions;
using Xbim.Ifc4x3.Kernel;
//## Custom using statements
//##


namespace Xbim.Ifc4x3.Kernel
{
	[ExpressType("IfcSimplePropertyTemplate", 1267)]
	// ReSharper disable once PartialTypeWithSinglePart
	public  partial class @IfcSimplePropertyTemplate : IfcPropertyTemplate, IInstantiableEntity, IContainsEntityReferences, IEquatable<@IfcSimplePropertyTemplate>
	{

		//internal constructor makes sure that objects are not created outside of the model/ assembly controlled area
		internal IfcSimplePropertyTemplate(IModel model, int label, bool activated) : base(model, label, activated)  
		{
		}

		#region Explicit attribute fields
		private IfcSimplePropertyTemplateTypeEnum? _templateType;
		private IfcLabel? _primaryMeasureType;
		private IfcLabel? _secondaryMeasureType;
		private IfcPropertyEnumeration _enumerators;
		private IfcUnit _primaryUnit;
		private IfcUnit _secondaryUnit;
		private IfcLabel? _expression;
		private IfcStateEnum? _accessState;
		#endregion
	
		#region Explicit attribute properties
		[EntityAttribute(5, EntityAttributeState.Optional, EntityAttributeType.Enum, EntityAttributeType.None, null, null, 9)]
		public IfcSimplePropertyTemplateTypeEnum? @TemplateType 
		{ 
			get 
			{
				if(_activated) return _templateType;
				Activate();
				return _templateType;
			} 
			set
			{
				SetValue( v =>  _templateType = v, _templateType, value,  "TemplateType", 5);
			} 
		}	
		[EntityAttribute(6, EntityAttributeState.Optional, EntityAttributeType.None, EntityAttributeType.None, null, null, 10)]
		public IfcLabel? @PrimaryMeasureType 
		{ 
			get 
			{
				if(_activated) return _primaryMeasureType;
				Activate();
				return _primaryMeasureType;
			} 
			set
			{
				SetValue( v =>  _primaryMeasureType = v, _primaryMeasureType, value,  "PrimaryMeasureType", 6);
			} 
		}	
		[EntityAttribute(7, EntityAttributeState.Optional, EntityAttributeType.None, EntityAttributeType.None, null, null, 11)]
		public IfcLabel? @SecondaryMeasureType 
		{ 
			get 
			{
				if(_activated) return _secondaryMeasureType;
				Activate();
				return _secondaryMeasureType;
			} 
			set
			{
				SetValue( v =>  _secondaryMeasureType = v, _secondaryMeasureType, value,  "SecondaryMeasureType", 7);
			} 
		}	
		[EntityAttribute(8, EntityAttributeState.Optional, EntityAttributeType.Class, EntityAttributeType.None, null, null, 12)]
		public IfcPropertyEnumeration @Enumerators 
		{ 
			get 
			{
				if(_activated) return _enumerators;
				Activate();
				return _enumerators;
			} 
			set
			{
				if (value != null && !(ReferenceEquals(Model, value.Model)))
					throw new XbimException("Cross model entity assignment.");
				SetValue( v =>  _enumerators = v, _enumerators, value,  "Enumerators", 8);
			} 
		}	
		[EntityAttribute(9, EntityAttributeState.Optional, EntityAttributeType.Class, EntityAttributeType.None, null, null, 13)]
		public IfcUnit @PrimaryUnit 
		{ 
			get 
			{
				if(_activated) return _primaryUnit;
				Activate();
				return _primaryUnit;
			} 
			set
			{
				if (value != null && !(ReferenceEquals(Model, value.Model)))
					throw new XbimException("Cross model entity assignment.");
				SetValue( v =>  _primaryUnit = v, _primaryUnit, value,  "PrimaryUnit", 9);
			} 
		}	
		[EntityAttribute(10, EntityAttributeState.Optional, EntityAttributeType.Class, EntityAttributeType.None, null, null, 14)]
		public IfcUnit @SecondaryUnit 
		{ 
			get 
			{
				if(_activated) return _secondaryUnit;
				Activate();
				return _secondaryUnit;
			} 
			set
			{
				if (value != null && !(ReferenceEquals(Model, value.Model)))
					throw new XbimException("Cross model entity assignment.");
				SetValue( v =>  _secondaryUnit = v, _secondaryUnit, value,  "SecondaryUnit", 10);
			} 
		}	
		[EntityAttribute(11, EntityAttributeState.Optional, EntityAttributeType.None, EntityAttributeType.None, null, null, 15)]
		public IfcLabel? @Expression 
		{ 
			get 
			{
				if(_activated) return _expression;
				Activate();
				return _expression;
			} 
			set
			{
				SetValue( v =>  _expression = v, _expression, value,  "Expression", 11);
			} 
		}	
		[EntityAttribute(12, EntityAttributeState.Optional, EntityAttributeType.Enum, EntityAttributeType.None, null, null, 16)]
		public IfcStateEnum? @AccessState 
		{ 
			get 
			{
				if(_activated) return _accessState;
				Activate();
				return _accessState;
			} 
			set
			{
				SetValue( v =>  _accessState = v, _accessState, value,  "AccessState", 12);
			} 
		}	
		#endregion




		#region IPersist implementation
		public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex)
		{
			switch (propIndex)
			{
				case 0: 
				case 1: 
				case 2: 
				case 3: 
					base.Parse(propIndex, value, nestedIndex); 
					return;
				case 4: 
                    _templateType = (IfcSimplePropertyTemplateTypeEnum) System.Enum.Parse(typeof (IfcSimplePropertyTemplateTypeEnum), value.EnumVal, true);
					return;
				case 5: 
					_primaryMeasureType = value.StringVal;
					return;
				case 6: 
					_secondaryMeasureType = value.StringVal;
					return;
				case 7: 
					_enumerators = (IfcPropertyEnumeration)(value.EntityVal);
					return;
				case 8: 
					_primaryUnit = (IfcUnit)(value.EntityVal);
					return;
				case 9: 
					_secondaryUnit = (IfcUnit)(value.EntityVal);
					return;
				case 10: 
					_expression = value.StringVal;
					return;
				case 11: 
                    _accessState = (IfcStateEnum) System.Enum.Parse(typeof (IfcStateEnum), value.EnumVal, true);
					return;
				default:
					throw new XbimParserException(string.Format("Attribute index {0} is out of range for {1}", propIndex + 1, GetType().Name.ToUpper()));
			}
		}
		#endregion

		#region Equality comparers and operators
        public bool Equals(@IfcSimplePropertyTemplate other)
	    {
	        return this == other;
	    }
        #endregion

		#region IContainsEntityReferences
		IEnumerable<IPersistEntity> IContainsEntityReferences.References 
		{
			get 
			{
				if (@OwnerHistory != null)
					yield return @OwnerHistory;
				if (@Enumerators != null)
					yield return @Enumerators;
				if (@PrimaryUnit != null)
					yield return @PrimaryUnit;
				if (@SecondaryUnit != null)
					yield return @SecondaryUnit;
			}
		}
		#endregion

		#region Custom code (will survive code regeneration)
		//## Custom code
		//##
		#endregion
	}
}