using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;


using CategoryTheory;

namespace Motion6D
{
    [Serializable()]
    public class PositionIndicatorLink : ISerializable, ICategoryArrow, IRemovableObject
    {
        #region Fields
        object obj;

        PositionCollectionIndicator indicator;

        IPositionCollection collecion;
        #endregion


        #region Ctor

        public PositionIndicatorLink()
        {
        }

        private PositionIndicatorLink(SerializationInfo info, StreamingContext context)
        {
        }

        #endregion

        #region ISerializable Members

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {

        }

        #endregion

        #region ICategoryArrow Members

        ICategoryObject ICategoryArrow.Source
        {
            get
            {
                return indicator;
            }
            set
            {
                if (!(value is PositionCollectionIndicator))
                {
                    CategoryException.ThrowIllegalSourceException();
                }
                indicator = value as PositionCollectionIndicator;
            }
        }

        ICategoryObject ICategoryArrow.Target
        {
            get
            {
                return collecion as ICategoryObject;
            }
            set
            {
                if (!(value is IPositionCollection))
                {
                    CategoryException.ThrowIllegalTargetException();
                }
                collecion = value as IPositionCollection;
                indicator.Positions = collecion;
            }
        }

        bool ICategoryArrow.IsMonomorphism
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        bool ICategoryArrow.IsEpimorphism
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        bool ICategoryArrow.IsIsomorphism
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        ICategoryArrow ICategoryArrow.Compose(ICategory category, ICategoryArrow next)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        #region IAssociatedObject Members

        object IAssociatedObject.Object
        {
            get
            {
                return obj;
            }
            set
            {
                obj = value;
            }
        }

        #endregion

        #region IRemovableObject Members

        void IRemovableObject.RemoveObject()
        {
            indicator.Positions = null;
        }

        #endregion
    }
}
