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

namespace FormulaEditor
{
    /// <summary>
    /// Symbol of date time
    /// </summary>
    [Serializable()]
    public class DateTimeSymbol : SimpleSymbol, IObjectOperation, IOperationAcceptor, IOperationDetector
    {
        protected DateTime dt;
        static public readonly DateTimeSymbol Object = new DateTimeSymbol();
        public DateTimeSymbol()
            : base('d', 0, false, true, "Date Time")
        {
        }

        public override object Clone()
        {
            DateTimeSymbol sym = new DateTimeSymbol();
            sym.dt = dt;
            return sym;
        }

        public DateTimeSymbol(DateTimeSymbol s)
            : base(s)
        {
            dt = s.dt;
        }

        public DateTimeSymbol(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            dt = (DateTime)info.GetValue("DateTime", typeof(DateTime));    
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            info.AddValue("DateTime", dt, typeof(DateTime));
        }


        public override string ToString()
        {
            return dt.ToLongDateString() + " "  + dt.ToLongTimeString();
        }

        /// <summary>
        /// Date time
        /// </summary>
        public DateTime DateTime
        {
            set
            {
                dt = value;
            }
        }


        #region IObjectOperation Members

        int IObjectOperation.Arity
        {
            get { return 0; }
        }

        object IObjectOperation.this[object[] x]
        {
            get { return dt; }
        }

        object IObjectOperation.ReturnType
        {
            get { return Object; }
        }

        bool IObjectOperation.IsPowered
        {
            get { return false; }
        }

        #endregion

        #region IOperationAcceptor Members

        IObjectOperation IOperationAcceptor.Accept(object type)
        {
            return this;
        }

        #endregion

        #region IOperationDetector Members

        IOperationAcceptor IOperationDetector.Detect(MathSymbol s)
        {
            if (s is DateTimeSymbol)
            {
                DateTimeSymbol dt = s as DateTimeSymbol;
                return dt;
            }
            return null;
        }

        #endregion
}
}
