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


namespace Xbim.Ifc4x3.CostResource
{
	[ExpressType("IfcCurrencyRelationship", 195)]
	// ReSharper disable once PartialTypeWithSinglePart
	public  partial class @IfcCurrencyRelationship : IfcResourceLevelRelationship, IInstantiableEntity, IContainsEntityReferences, IEquatable<@IfcCurrencyRelationship>
	{

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

		#region Explicit attribute fields
		private IfcMonetaryUnit _relatingMonetaryUnit;
		private IfcMonetaryUnit _relatedMonetaryUnit;
		private IfcPositiveRatioMeasure _exchangeRate;
		private IfcDateTime? _rateDateTime;
		private IfcLibraryInformation _rateSource;
		#endregion
	
		#region Explicit attribute properties
		[EntityAttribute(3, EntityAttributeState.Mandatory, EntityAttributeType.Class, EntityAttributeType.None, null, null, 3)]
		public IfcMonetaryUnit @RelatingMonetaryUnit 
		{ 
			get 
			{
				if(_activated) return _relatingMonetaryUnit;
				Activate();
				return _relatingMonetaryUnit;
			} 
			set
			{
				if (value != null && !(ReferenceEquals(Model, value.Model)))
					throw new XbimException("Cross model entity assignment.");
				SetValue( v =>  _relatingMonetaryUnit = v, _relatingMonetaryUnit, value,  "RelatingMonetaryUnit", 3);
			} 
		}	
		[EntityAttribute(4, EntityAttributeState.Mandatory, EntityAttributeType.Class, EntityAttributeType.None, null, null, 4)]
		public IfcMonetaryUnit @RelatedMonetaryUnit 
		{ 
			get 
			{
				if(_activated) return _relatedMonetaryUnit;
				Activate();
				return _relatedMonetaryUnit;
			} 
			set
			{
				if (value != null && !(ReferenceEquals(Model, value.Model)))
					throw new XbimException("Cross model entity assignment.");
				SetValue( v =>  _relatedMonetaryUnit = v, _relatedMonetaryUnit, value,  "RelatedMonetaryUnit", 4);
			} 
		}	
		[EntityAttribute(5, EntityAttributeState.Mandatory, EntityAttributeType.None, EntityAttributeType.None, null, null, 5)]
		public IfcPositiveRatioMeasure @ExchangeRate 
		{ 
			get 
			{
				if(_activated) return _exchangeRate;
				Activate();
				return _exchangeRate;
			} 
			set
			{
				SetValue( v =>  _exchangeRate = v, _exchangeRate, value,  "ExchangeRate", 5);
			} 
		}	
		[EntityAttribute(6, EntityAttributeState.Optional, EntityAttributeType.None, EntityAttributeType.None, null, null, 6)]
		public IfcDateTime? @RateDateTime 
		{ 
			get 
			{
				if(_activated) return _rateDateTime;
				Activate();
				return _rateDateTime;
			} 
			set
			{
				SetValue( v =>  _rateDateTime = v, _rateDateTime, value,  "RateDateTime", 6);
			} 
		}	
		[EntityAttribute(7, EntityAttributeState.Optional, EntityAttributeType.Class, EntityAttributeType.None, null, null, 7)]
		public IfcLibraryInformation @RateSource 
		{ 
			get 
			{
				if(_activated) return _rateSource;
				Activate();
				return _rateSource;
			} 
			set
			{
				if (value != null && !(ReferenceEquals(Model, value.Model)))
					throw new XbimException("Cross model entity assignment.");
				SetValue( v =>  _rateSource = v, _rateSource, value,  "RateSource", 7);
			} 
		}	
		#endregion




		#region IPersist implementation
		public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex)
		{
			switch (propIndex)
			{
				case 0: 
				case 1: 
					base.Parse(propIndex, value, nestedIndex); 
					return;
				case 2: 
					_relatingMonetaryUnit = (IfcMonetaryUnit)(value.EntityVal);
					return;
				case 3: 
					_relatedMonetaryUnit = (IfcMonetaryUnit)(value.EntityVal);
					return;
				case 4: 
					_exchangeRate = value.RealVal;
					return;
				case 5: 
					_rateDateTime = value.StringVal;
					return;
				case 6: 
					_rateSource = (IfcLibraryInformation)(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(@IfcCurrencyRelationship other)
	    {
	        return this == other;
	    }
        #endregion

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

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