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

using CategoryTheory;

namespace Motion6D
{
    [Serializable()]
    public class CameraLink : ISerializable, ICategoryArrow, IRemovableObject
    {
        #region Fields

        private Camera camera;

        private IPosition position;

        private object obj;

        #endregion

        #region Ctor

        public CameraLink()
        {
        }

        private CameraLink(SerializationInfo info, StreamingContext context)
        {
        }

        #endregion


        #region ISerializable Members

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

        #endregion

        #region ICategoryArrow Members

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

        ICategoryObject ICategoryArrow.Target
        {
            get
            {
                return position as ICategoryObject;
            }
            set
            {
                if (!(value is IPosition))
                {
                    CategoryException.ThrowIllegalTargetException();
                }
                position = value as IPosition;
                object obj = position.Parameters;
                if (!(obj is IVisible))
                {
                    CategoryException.ThrowIllegalTargetException();
                }
                camera.AddVisible(position);
            }
        }

        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()
        {
            camera.RemoveVisible(position);
        }

        #endregion
    }
}
