// ------------------------------------------------------------------------------
// <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.Ifc4.Interfaces;
using System.Collections.Generic;
using System.Linq;
using Xbim.Common;
using Xbim.Ifc4x3.MeasureResource;

//## Custom using statements
//##

// ReSharper disable once CheckNamespace
namespace Xbim.Ifc4x3.GeometryResource
{
	public partial class @IfcIndexedPolyCurve : IIfcIndexedPolyCurve
	{

		[CrossSchemaAttribute(typeof(IIfcIndexedPolyCurve), 1)]
		IIfcCartesianPointList IIfcIndexedPolyCurve.Points 
		{ 
			get
			{
				return Points;
			} 
			set
			{
				Points = value as GeometricModelResource.IfcCartesianPointList;
				
			}
		}

		[CrossSchemaAttribute(typeof(IIfcIndexedPolyCurve), 2)]
		IItemSet<IIfcSegmentIndexSelect> IIfcIndexedPolyCurve.Segments 
		{ 
			get
			{
			
				return _segmentsIfc4 ?? (_segmentsIfc4 = new Common.Collections.ExtendedItemSet<IfcSegmentIndexSelect, IIfcSegmentIndexSelect>(
                    Segments, 
                    new ItemSet<IIfcSegmentIndexSelect>(this, 0, -2), 
					SegmentsToIfc4, 
                    SegmentsToIfc2X3));
			} 
		}

		//private field to hold any extended data
		private IItemSet<IIfcSegmentIndexSelect> _segmentsIfc4;
		//transformation function to convert/cast IFC2x3 data to appear as IFC4
		private static IIfcSegmentIndexSelect SegmentsToIfc4 (IfcSegmentIndexSelect member)
		{
			if (member == null) 
				return null;
			switch (member.GetType().Name)
			{
				case "IfcArcIndex":
					//## Handle defined type IfcArcIndex which is not a part of the target select interface IItemSet<IIfcSegmentIndexSelect> in property Segments
					return new Ifc4.GeometryResource.IfcArcIndex((member.Value as IEnumerable<IfcPositiveInteger>).Select(p => new Ifc4.MeasureResource.IfcPositiveInteger((long)p.Value)).ToList());
					//##
				case "IfcLineIndex":
					//## Handle defined type IfcLineIndex which is not a part of the target select interface IItemSet<IIfcSegmentIndexSelect> in property Segments
					return new Ifc4.GeometryResource.IfcLineIndex((member.Value as IEnumerable<IfcPositiveInteger>).Select(p => new Ifc4.MeasureResource.IfcPositiveInteger((long)p.Value)).ToList());
					//##
				default:
					throw new System.NotSupportedException();
			}
		}

		//transformation function to convert/cast IFC4 data to appear as IFC2x3 if possible
		private static IfcSegmentIndexSelect SegmentsToIfc2X3 (IIfcSegmentIndexSelect member){
			if (member == null) 
				return null;
			var name = member.GetType().Name;
			switch (name)
			{
				case "IfcArcIndex":
					//## Handle return defined type IfcArcIndex which is not a part of the target select interface IfcSegmentIndexSelect in property Segments
					return new IfcArcIndex((member.Value as IEnumerable<Ifc4.MeasureResource.IfcPositiveInteger>).Select(p => new IfcPositiveInteger((long)p.Value)).ToList());
					//##
				case "IfcLineIndex":
					//## Handle return defined type IfcLineIndex which is not a part of the target select interface IfcSegmentIndexSelect in property Segments
					return new IfcLineIndex((member.Value as IEnumerable<Ifc4.MeasureResource.IfcPositiveInteger>).Select(p => new IfcPositiveInteger((long)p.Value)).ToList());
					//##
				default:
					throw new System.NotSupportedException();
			}
		}

		[CrossSchemaAttribute(typeof(IIfcIndexedPolyCurve), 3)]
		Ifc4.MeasureResource.IfcBoolean? IIfcIndexedPolyCurve.SelfIntersect 
		{ 
			get
			{
				if (!SelfIntersect.HasValue) return null;
				return new Ifc4.MeasureResource.IfcBoolean(SelfIntersect.Value);
			} 
			set
			{
				SelfIntersect = value.HasValue ? 
					new MeasureResource.IfcBoolean(value.Value) :  
					 new MeasureResource.IfcBoolean?() ;
				
			}
		}
	//## Custom code
	//##
	}
}