using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using static RGDWCSServices.Enum;

namespace RGDWCSServices.WCS
{
    /// <summary>3.1入库任务下发
    /// 智能仓储系统（wms）在相关的入库业务流程中，手动启动智能仓储系统（wms）下发的入库任务。并调用入库任务启动接口，将入库站台号发送至表库控制系统（wcs）。表库控制系统（wcs）将该站台的输送机切换为入库模式，若无法切换则返回失败标志。
    /// </summary>
    public class startInTask : HouseBase
    {
        /// <summary>
        /// 入参定义
        /// </summary>
        [Serializable]
        public class PARA
        {
            private string _wh_id;
            private string _equip_type;
            private string _task_no;
            private string _platform_no;
            private string _io_wh_sort_code;
            private string _single_standard;
            private string _qty;
            private List<LOCATION> _loc_list;

            /// <summary>
            /// 库房编号
            /// </summary>
            public string QTY
            {
                get { return this._qty; }
                set { this._qty = value; }
            }

            /// <summary>
            /// 库房编号
            /// </summary>
            public string WH_ID
            {
                get { return this._wh_id; }
                set { this._wh_id = value; }
            }

            /// <summary>
            /// <para>设备类型</para>
            /// <para>下发库房的设备类型：01单相表 02三相表 03互感器 04采集终端 05周转箱 06通信模块。</para>
            /// </summary>
            public string EQUIP_TYPE
            {
                get { return this._equip_type; }
                set { this._equip_type = value; }
            }
            /// <summary>
            /// 任务号
            /// </summary>
            public string TASK_NO
            {
                get { return this._task_no; }
                set { this._task_no = value; }
            }
            /// <summary>
            /// 入库站台号
            /// </summary>
            public string PLATFORM_NO
            {
                get { return this._platform_no; }
                set { this._platform_no = value; }
            }
            /// <summary>
            /// 入库站台号
            /// </summary>
            public string IO_WH_SORT_CODE
            {
                get { return this._io_wh_sort_code; }
                set { this._io_wh_sort_code = value; }
            }
            /// <summary>
            /// 是否单品规。0：否；1：是。
            /// </summary>
            public string SINGLE_STANDARD
            {
                get { return this._single_standard; }
                set { this._single_standard = value; }
            }
            /// <summary>
            /// 目标货位
            /// </summary>
            [XmlArrayItem(ElementName = "LOC")]
            public List<LOCATION> LOC_LIST
            {
                get { return this._loc_list; }
                set { this._loc_list = value; }
            }
        }

        /// <summary>
        /// 出参定义
        /// </summary>
        [Serializable]
        public class DATA : Base.OutPara
        {

        }

        /// <summary>
        /// 入参实体
        /// </summary>
        private PARA _inPara;

        /// <summary>
        /// 出参实体
        /// </summary>
        private DATA _outPara;

        /// <summary>
        /// 构造函数
        /// </summary>
        public startInTask()
        {
            this._outPara = new DATA();
        }

        /// <summary>
        /// 通知
        /// </summary>
        /// <param name="sXmlIn">入参</param>
        /// <param name="sXmlOut">出参</param>
        /// <returns>执行结果</returns>
        public bool Notify(string sXmlIn, out string sXmlOut)
        {
            bool bResult = true;

            string sResult = string.Empty;

            sXmlOut = string.Empty;

            try
            {
                this._inPara = this.DeSerialize<PARA>(sXmlIn);

                bResult = null != this._inPara;

                if (!bResult)
                {
                    sResult = string.Format("入参错误（格式错误）");

                    return bResult;
                }
                //if (_inPara.PLATFORM_NO == "12002")
                //{
                this.START_INTASK(_inPara.QTY);
                bResult = this.START_INTASK(_inPara.WH_ID, _inPara.EQUIP_TYPE, _inPara.TASK_NO, _inPara.PLATFORM_NO, _inPara.IO_WH_SORT_CODE, _inPara.LOC_LIST, _inPara.SINGLE_STANDARD, sXmlIn, out sResult);
                //}
                //else
                //{
                //    HiveService.RGDWCSServiceClient ws = new HiveService.RGDWCSServiceClient();
                //    sXmlOut = ws.startInTask(sXmlIn);
                //    this._outPara = this.DeSerialize<DATA>(sXmlOut);
                //    bResult = _outPara.RESULT_FLAG == "1";
                //}
            }
            catch (Exception ex)
            {
                bResult = false;

                sResult = string.Format(ex.Message);
            }
            finally
            {
                if (bResult)
                {
                    this._outPara.RESULT_FLAG = Enum.RESULT_FLAG.Success.ToString("d");
                }
                else
                {
                    this._outPara.RESULT_FLAG = Enum.RESULT_FLAG.Fail.ToString("d");
                }

                this._outPara.ERROR_INFO = sResult;

                sXmlOut = this.Serializer<DATA>(this._outPara);
            }

            return bResult;
        }
    }
}
