// ------------------------------------------------------------------------------
// <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.PropertyResource;
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.Ifc2x3.DateTimeResource;
//## Custom using statements
//##


namespace Xbim.Ifc2x3.DateTimeResource
{
	[ExpressType("IfcCalendarDate", 407)]
	// ReSharper disable once PartialTypeWithSinglePart
	public  partial class @IfcCalendarDate : PersistEntity, IInstantiableEntity, IfcDateTimeSelect, IfcObjectReferenceSelect, IEquatable<@IfcCalendarDate>
	{

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

		#region Explicit attribute fields
		private IfcDayInMonthNumber _dayComponent;
		private IfcMonthInYearNumber _monthComponent;
		private IfcYearNumber _yearComponent;
		#endregion
	
		#region Explicit attribute properties
		[EntityAttribute(1, EntityAttributeState.Mandatory, EntityAttributeType.None, EntityAttributeType.None, null, null, 1)]
		public IfcDayInMonthNumber @DayComponent 
		{ 
			get 
			{
				if(_activated) return _dayComponent;
				Activate();
				return _dayComponent;
			} 
			set
			{
				SetValue( v =>  _dayComponent = v, _dayComponent, value,  "DayComponent", 1);
			} 
		}	
		[EntityAttribute(2, EntityAttributeState.Mandatory, EntityAttributeType.None, EntityAttributeType.None, null, null, 2)]
		public IfcMonthInYearNumber @MonthComponent 
		{ 
			get 
			{
				if(_activated) return _monthComponent;
				Activate();
				return _monthComponent;
			} 
			set
			{
				SetValue( v =>  _monthComponent = v, _monthComponent, value,  "MonthComponent", 2);
			} 
		}	
		[EntityAttribute(3, EntityAttributeState.Mandatory, EntityAttributeType.None, EntityAttributeType.None, null, null, 3)]
		public IfcYearNumber @YearComponent 
		{ 
			get 
			{
				if(_activated) return _yearComponent;
				Activate();
				return _yearComponent;
			} 
			set
			{
				SetValue( v =>  _yearComponent = v, _yearComponent, value,  "YearComponent", 3);
			} 
		}	
		#endregion




		#region IPersist implementation
		public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex)
		{
			switch (propIndex)
			{
				case 0: 
					_dayComponent = value.IntegerVal;
					return;
				case 1: 
					_monthComponent = value.IntegerVal;
					return;
				case 2: 
					_yearComponent = value.IntegerVal;
					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(@IfcCalendarDate other)
	    {
	        return this == other;
	    }
        #endregion

		#region Custom code (will survive code regeneration)
		//## Custom code
		public override string ToString ()
        {
            return string.Format ("{0}-{1}-{2}", YearComponent, MonthComponent, DayComponent);
        }
		//##
		#endregion
	}
}