using System.Threading.Tasks;

namespace WS
{
    ///<summary>操作基类</summary>
    public abstract class BaseOperate : WSComponent
    {
        protected WSTaskComponent vtask;
        ///<summary>任务组件</summary>
        protected WSTaskComponent vTask
        {
            get
            {
                if (vtask == null)
                    vtask = (WSTaskComponent)Parent;
                return vtask;
            }
        }
        ///<summary>Id</summary>
        public int Id;
        ///<summary>流程描述/名称</summary>
        public string Describe;
        ///<summary>是否完成</summary>
        public bool IsComplete;

        ///<summary>初始化操作数据</summary>
        ///<param name="json">数据</param>
        public virtual void InitData(string json) { }

        ///<summary>初始化</summary>
        public abstract void Init();

        ///<summary>开始操作</summary>
        public abstract void StartOperate();

        ///<summary>帧循环</summary>
        public abstract void Update();

        ///<summary>提示</summary>
        public virtual void Prompt() { }

        ///<summary>使当前流程执行到 开始 状态 (需要考虑到正在执行当前流程的情况)</summary>
        public virtual Task StartState() { return null; }

        ///<summary>使当前流程执行到 结束 状态 (需要考虑到正在执行当前流程的情况)</summary>
        public virtual Task EndState() { return null; }

        public override void Dispose()
        {
            base.Dispose();
            vtask = null;
            Id = 0;
            Describe = "";
            IsComplete = false;
        }
    }

    ///<summary>操作组件</summary>
    public abstract class OperateComponent<T> : BaseOperate where T : class
    {
        ///<summary>操作</summary>
        public T OperateData;

        public override void InitData(string json)
        {
            OperateData = LitJson.JsonMapper.ToObject<T>(json);
        }
    }
}