// ------------------------------------------------------------------------------
// <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.CostResource;
using Xbim.Ifc4x3.MeasureResource;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using Xbim.Common.Metadata;
using Xbim.Common;
using Xbim.Common.Exceptions;
using Xbim.Ifc4x3.ConstraintResource;
//## Custom using statements
//##


namespace Xbim.Ifc4x3.ConstraintResource
{
	[ExpressType("IfcReference", 1244)]
	// ReSharper disable once PartialTypeWithSinglePart
	public  partial class @IfcReference : PersistEntity, IInstantiableEntity, IfcAppliedValueSelect, IfcMetricValueSelect, IContainsEntityReferences, IEquatable<@IfcReference>
	{

		//internal constructor makes sure that objects are not created outside of the model/ assembly controlled area
		internal IfcReference(IModel model, int label, bool activated) : base(model, label, activated)  
		{
			_listPositions = new OptionalItemSet<IfcInteger>( this, 0,  4);
		}

		#region Explicit attribute fields
		private IfcIdentifier? _typeIdentifier;
		private IfcIdentifier? _attributeIdentifier;
		private IfcLabel? _instanceName;
		private readonly OptionalItemSet<IfcInteger> _listPositions;
		private IfcReference _innerReference;
		#endregion
	
		#region Explicit attribute properties
		[EntityAttribute(1, EntityAttributeState.Optional, EntityAttributeType.None, EntityAttributeType.None, null, null, 1)]
		public IfcIdentifier? @TypeIdentifier 
		{ 
			get 
			{
				if(_activated) return _typeIdentifier;
				Activate();
				return _typeIdentifier;
			} 
			set
			{
				SetValue( v =>  _typeIdentifier = v, _typeIdentifier, value,  "TypeIdentifier", 1);
			} 
		}	
		[EntityAttribute(2, EntityAttributeState.Optional, EntityAttributeType.None, EntityAttributeType.None, null, null, 2)]
		public IfcIdentifier? @AttributeIdentifier 
		{ 
			get 
			{
				if(_activated) return _attributeIdentifier;
				Activate();
				return _attributeIdentifier;
			} 
			set
			{
				SetValue( v =>  _attributeIdentifier = v, _attributeIdentifier, value,  "AttributeIdentifier", 2);
			} 
		}	
		[EntityAttribute(3, EntityAttributeState.Optional, EntityAttributeType.None, EntityAttributeType.None, null, null, 3)]
		public IfcLabel? @InstanceName 
		{ 
			get 
			{
				if(_activated) return _instanceName;
				Activate();
				return _instanceName;
			} 
			set
			{
				SetValue( v =>  _instanceName = v, _instanceName, value,  "InstanceName", 3);
			} 
		}	
		[EntityAttribute(4, EntityAttributeState.Optional, EntityAttributeType.List, EntityAttributeType.None, new int [] { 1 }, new int [] { -1 }, 4)]
		public IOptionalItemSet<IfcInteger> @ListPositions 
		{ 
			get 
			{
				if(_activated) return _listPositions;
				Activate();
				return _listPositions;
			} 
		}	
		[EntityAttribute(5, EntityAttributeState.Optional, EntityAttributeType.Class, EntityAttributeType.None, null, null, 5)]
		public IfcReference @InnerReference 
		{ 
			get 
			{
				if(_activated) return _innerReference;
				Activate();
				return _innerReference;
			} 
			set
			{
				if (value != null && !(ReferenceEquals(Model, value.Model)))
					throw new XbimException("Cross model entity assignment.");
				SetValue( v =>  _innerReference = v, _innerReference, value,  "InnerReference", 5);
			} 
		}	
		#endregion




		#region IPersist implementation
		public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex)
		{
			switch (propIndex)
			{
				case 0: 
					_typeIdentifier = value.StringVal;
					return;
				case 1: 
					_attributeIdentifier = value.StringVal;
					return;
				case 2: 
					_instanceName = value.StringVal;
					return;
				case 3: 
					_listPositions.InternalAdd(value.IntegerVal);
					return;
				case 4: 
					_innerReference = (IfcReference)(value.EntityVal);
					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(@IfcReference other)
	    {
	        return this == other;
	    }
        #endregion

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

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