// ------------------------------------------------------------------------------
// <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.Ifc2x3.GeometryResource;
using Xbim.Ifc2x3.ProfileResource;
using System;
using System.Collections.Generic;
using System.Linq;
using Xbim.Common;
using Xbim.Common.Exceptions;
using Xbim.Ifc2x3.GeometricConstraintResource;
//## Custom using statements
//##


namespace Xbim.Ifc2x3.GeometricConstraintResource
{
	[ExpressType("IfcConnectionPortGeometry", 713)]
	// ReSharper disable once PartialTypeWithSinglePart
	public  partial class @IfcConnectionPortGeometry : IfcConnectionGeometry, IInstantiableEntity, IContainsEntityReferences, IEquatable<@IfcConnectionPortGeometry>
	{

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

		#region Explicit attribute fields
		private IfcAxis2Placement _locationAtRelatingElement;
		private IfcAxis2Placement _locationAtRelatedElement;
		private IfcProfileDef _profileOfPort;
		#endregion
	
		#region Explicit attribute properties
		[EntityAttribute(1, EntityAttributeState.Mandatory, EntityAttributeType.Class, EntityAttributeType.None, null, null, 1)]
		public IfcAxis2Placement @LocationAtRelatingElement 
		{ 
			get 
			{
				if(_activated) return _locationAtRelatingElement;
				Activate();
				return _locationAtRelatingElement;
			} 
			set
			{
				if (value != null && !(ReferenceEquals(Model, value.Model)))
					throw new XbimException("Cross model entity assignment.");
				SetValue( v =>  _locationAtRelatingElement = v, _locationAtRelatingElement, value,  "LocationAtRelatingElement", 1);
			} 
		}	
		[EntityAttribute(2, EntityAttributeState.Optional, EntityAttributeType.Class, EntityAttributeType.None, null, null, 2)]
		public IfcAxis2Placement @LocationAtRelatedElement 
		{ 
			get 
			{
				if(_activated) return _locationAtRelatedElement;
				Activate();
				return _locationAtRelatedElement;
			} 
			set
			{
				if (value != null && !(ReferenceEquals(Model, value.Model)))
					throw new XbimException("Cross model entity assignment.");
				SetValue( v =>  _locationAtRelatedElement = v, _locationAtRelatedElement, value,  "LocationAtRelatedElement", 2);
			} 
		}	
		[EntityAttribute(3, EntityAttributeState.Mandatory, EntityAttributeType.Class, EntityAttributeType.None, null, null, 3)]
		public IfcProfileDef @ProfileOfPort 
		{ 
			get 
			{
				if(_activated) return _profileOfPort;
				Activate();
				return _profileOfPort;
			} 
			set
			{
				if (value != null && !(ReferenceEquals(Model, value.Model)))
					throw new XbimException("Cross model entity assignment.");
				SetValue( v =>  _profileOfPort = v, _profileOfPort, value,  "ProfileOfPort", 3);
			} 
		}	
		#endregion




		#region IPersist implementation
		public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex)
		{
			switch (propIndex)
			{
				case 0: 
					_locationAtRelatingElement = (IfcAxis2Placement)(value.EntityVal);
					return;
				case 1: 
					_locationAtRelatedElement = (IfcAxis2Placement)(value.EntityVal);
					return;
				case 2: 
					_profileOfPort = (IfcProfileDef)(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(@IfcConnectionPortGeometry other)
	    {
	        return this == other;
	    }
        #endregion

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

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