using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

using Cosmos.Common;
using Cosmos.UserFrame;
using Cosmos.BaseFrame;
using Cosmos.CommonManager;
using Cosmos.ServiceProvider;

namespace Cosmos.Service
{
    class VisitGovernment : IDataServiceUs
    {
        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private PosStatus m_cPosStatus = new PosStatus();                           //기본정보 참조
        //private TranStatus m_cTrnStatus = null;                                     // 거래정보 참조
        private INetworkHttp m_cNetworkHttp = null;
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        private IDataServiceUs m_cWebBiz = null;
        protected IDataCommonUs m_cDataCommon = null;                               // 판매공통 모듈

        public VisitGovernment()
        {
            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            //m_cTrnStatus = (TranStatus)StateObject.TRAN;    // POS 거래정보

            m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
            m_cNetworkHttp = (INetworkHttp)sManager.InitServiceInstance(ServiceLists.AGENT_NETWORK.DLL, ServiceLists.AGENT_NETWORK.NETWORK_HTTP);
            m_cWebBiz = (IDataServiceUs)sManager.InitServiceInstance(ServiceLists.BSV_BASIC.DLL, ServiceLists.BSV_BASIC.WEB_POS);

        }

        /// <summary>
        /// 관공서 방문알림 서버 전송
        /// </summary>
        /// <returns></returns>
        public string Execute(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            int nRet = BaseCom.NG;

            string sUrl = string.Empty;
            string sHttpUrl = string.Empty;
            string sHttpParam = string.Empty;

            try
            {
                Hashtable htRequest = new Hashtable();
                Hashtable htRspData = new Hashtable();

                htRequest.Add("BRAND_CD", m_cPosStatus.Base.BrandCd);
                htRequest.Add("STORE_CD", m_cPosStatus.Base.StoreNo);
                htRequest.Add("I_USER_NO", m_cPosStatus.Base.CashierNo);
                htRequest.Add("I_USER_NM", m_cPosStatus.Base.CashierName);

                sUrl = (string)m_cWebBiz.GetData(new string[] { PosKey.MENU_KEY.VISIT_GOVERNMENT_OFFICE });
                if (sUrl == null || sUrl == "") return sRet;

                if (sUrl.StartsWith("2") == true)           // 1: WEB POS, 2:WEB LINK
                {
                    sHttpUrl = CmUtil.MidH(sUrl, 31, 100).Trim();
                    sHttpParam = CmUtil.MidH(sUrl, 131, 100).Trim();
                }

                nRet = m_cNetworkHttp.HttpPOST_SendReceiveForGoverVisit(sHttpUrl, sHttpParam, htRequest, ref htRspData);
                if (nRet != BaseCom.NG)
                {
                    sRet = UserCom.RST_OK;
                }
  
                return sRet;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return sRet;
        }

        public object GetData(string[] aParam)
        {
            throw new NotImplementedException();
        }

        public string SetData(object oParam)
        {
            throw new NotImplementedException();
        }
    }
}
