/*
 * Command.cs --
 *
 * Copyright (c) 2007-2012 by Joe Mistachkin.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: $
 */

using System;
using Eagle._Attributes;
using Eagle._Components.Public;
using Eagle._Components.Public.Delegates;
using Eagle._Containers.Public;
using Eagle._Interfaces.Public;

namespace Eagle._Wrappers
{
    [ObjectId("ff6aa9bc-def1-4ae1-9264-e3d653374767")]
    internal sealed class Command : Default, ICommand
    {
        #region Public Constructors
        public Command(
            long token,
            ICommand command
            )
            : base(token)
        {
            this.command = command;
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Data
        internal ICommand command;
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region IIdentifier Members
        public IdentifierKind Kind
        {
            get { return (command != null) ? command.Kind : IdentifierKind.None; }
            set { if (command != null) { command.Kind = value; } }
        }

        ///////////////////////////////////////////////////////////////////////

        public Guid Id
        {
            get { return (command != null) ? command.Id : Guid.Empty; }
            set { if (command != null) { command.Id = value; } }
        }

        ///////////////////////////////////////////////////////////////////////

        public string Name
        {
            get { return (command != null) ? command.Name : null; }
            set { if (command != null) { command.Name = value; } }
        }

        ///////////////////////////////////////////////////////////////////////

        public string Group
        {
            get { return (command != null) ? command.Group : null; }
            set { if (command != null) { command.Group = value; } }
        }

        ///////////////////////////////////////////////////////////////////////

        public string Description
        {
            get { return (command != null) ? command.Description : null; }
            set { if (command != null) { command.Description = value; } }
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region IHaveClientData Members
        public IClientData ClientData
        {
            get { return (command != null) ? command.ClientData : null; }
            set { if (command != null) { command.ClientData = value; } }
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region IState Members
        public bool Initialized
        {
            get { return (command != null) ? command.Initialized : false; }
            set { if (command != null) { command.Initialized = value; } }
        }

        ///////////////////////////////////////////////////////////////////////

        public ReturnCode Initialize(
            Interpreter interpreter,
            IClientData clientData,
            ref Result result
            )
        {
            if (command != null)
                return command.Initialize(interpreter, clientData, ref result);
            else
                return ReturnCode.Error;
        }

        ///////////////////////////////////////////////////////////////////////

        public ReturnCode Terminate(
            Interpreter interpreter,
            IClientData clientData,
            ref Result result
            )
        {
            if (command != null)
                return command.Terminate(interpreter, clientData, ref result);
            else
                return ReturnCode.Error;
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region IDynamicExecute Members
        public ExecuteCallback Callback
        {
            get { return (command != null) ? command.Callback : null; }
            set { if (command != null) { command.Callback = value; } }
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region IEnsemble Members
        public EnsembleDictionary SubCommands
        {
            get { return (command != null) ? command.SubCommands : null; }
            set { if (command != null) { command.SubCommands = value; } }
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region IExecute Members
        public ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            if (command != null)
                return command.Execute(
                    interpreter, clientData, arguments, ref result);
            else
                return ReturnCode.Error;
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region IUsageData Members
        public bool ResetUsage(
            UsageType type,
            ref long value
            )
        {
            return (command != null) ?
                command.ResetUsage(type, ref value) : false;
        }

        ///////////////////////////////////////////////////////////////////////

        public bool GetUsage(
            UsageType type,
            ref long value
            )
        {
            return (command != null) ?
                command.GetUsage(type, ref value) : false;
        }

        ///////////////////////////////////////////////////////////////////////

        public bool SetUsage(
            UsageType type,
            ref long value
            )
        {
            return (command != null) ?
                command.SetUsage(type, ref value) : false;
        }

        ///////////////////////////////////////////////////////////////////////

        public bool AddUsage(
            UsageType type,
            long value
            )
        {
            return (command != null) ? command.AddUsage(type, value) : false;
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region ICommandData Members
        public string TypeName
        {
            get { return (command != null) ? command.TypeName : null; }
            set { if (command != null) { command.TypeName = value; } }
        }

        ///////////////////////////////////////////////////////////////////////

        public CommandFlags Flags
        {
            get { return (command != null) ? command.Flags : CommandFlags.None; }
            set { if (command != null) { command.Flags = value; } }
        }

        ///////////////////////////////////////////////////////////////////////

        public IPlugin Plugin
        {
            get { return (command != null) ? command.Plugin : null; }
            set { if (command != null) { command.Plugin = value; } }
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region ISyntax Members
        public string Syntax
        {
            get { return (command != null) ? command.Syntax : null; }
            set { if (command != null) { command.Syntax = value; } }
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region IWrapper Members
        public override bool IsDisposable
        {
            get { return false; }
        }

        ///////////////////////////////////////////////////////////////////////

        public override object Object
        {
            get { return command; }
        }
        #endregion
    }
}
