using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pluto.Api;
using Sdaleo.Systems.SQLServer;
using Sdaleo;
using PlutoServer.MSL.Connectors;
using Sdaleo.Systems.Advantage;
using RegistrationAPI;
using Pluto.Registration;

namespace PlutoServer.MSL
{
    /// <summary>
    /// Only used for Debugging / Testing 
    /// </summary>
    internal static class DEBUGGING_ONLY
    {
        #region Debug Step Credentials (For Testing)

        const string LYTEC_KEY = "$616866C0D12EC1641A5#L";
        const string MEDISOFT_KEY = "$616866C0D12EC1641A5#M";

        /// <summary>
        /// Advantage User Test Credential
        /// </summary>
        internal static AdvantageCredential AdvantageTestCredential = new AdvantageCredential(@"\\10.97.156.4\Medidata\Tutor\mwddf.add", "user", "password", AdvantageCredential.ServerType.REMOTE);

        /// <summary>
        /// Advantage Shared Test Credential
        /// </summary>
        internal static AdvantageCredential AdvantageTestSharedCredential = new AdvantageCredential(@"\\10.97.156.4\Medidata\SharedData.add", "SharedDataUser", "AndPassword", AdvantageCredential.ServerType.REMOTE);

        /// <summary>
        /// SQLServer User Test Credential
        /// </summary>
        internal static SQLServerCredential SQLServerTestCredential = new SQLServerCredential("10.97.156.22", "LytecMD", "Lytec Tutorial", "sa", "Clinical$1");

        /// <summary>
        /// SQLServer Shared Test Credential
        /// </summary>
        internal static SQLServerCredential SQLServerTestSharedCredential = new SQLServerCredential("10.97.156.22", "LytecMD", "Lytec SharedData", "sa", "Clinical$1");


        #endregion

        /// <summary>
        /// Called in Debug Mode to allow us to step into specific things and
        /// easier test them straight thru the service, called before OnStart(),
        /// makes it easier to directly test Medisoft/Lytec Connectors
        /// </summary>
        internal static void DEBUGSTEP_INTO()
        {
            MSLSpecific.Setup_Test_Logger();
            DBCache.IsMachine_Used_ForTesting = true;
            DBCache.TestMedisoftDBCredential = AdvantageTestCredential;
            DBCache.TestLytecUserDBCredential = SQLServerTestCredential;

            //Could you please run the script for IP address thing for orgs with key 2A66B402F-4041-E491M and E2G4Y3777-4F3E-BFEDL
            //SystemAccessVerifier v = new SystemAccessVerifier("CC67BA96B-4E85-57BBM");
            //SystemAccessVerifier v = new SystemAccessVerifier("930CY6704-42FE-1D1FL");
            //SystemAccessVerifier v = new SystemAccessVerifier("2A66B402F-4041-E491M"); // "$194E114069F204446A2#M"
            SystemAccessVerifier v = new SystemAccessVerifier("E2G4Y3777-4F3E-BFEDL"); // "$DE3BDE3F4E777F34E2E#L"
                        
            //string pin = RegistrationAPI.API.RetrieveUserApiKeyPin("CC67BA96B-4E85-57BBM");
            string apikey = v.SystemApiKey;

            Pluto.Registration.Host host = RegistrationAPI.API.GetApiMobile(v.SystemApiKey);
            string ip = host.host;
            int port = host.port;
            bool bTest = RegistrationAPI.API.IsApiMobileReachable(v.SystemApiKey);

            //RegistrationAPI.API.SetNetworkSettings("172.19.73.26", 443);
            RegistrationAPI.API.SetNetworkSettings("ppsmobile.mckesson.com", 443);
            //RegistrationAPI.API.SetNetworkSettings("services.ndchealthvar.com", 443);
            string strApiKey;
            string strPin;
            bool bSuccess = RegistrationAPI.API.RegisterNewServerPractice(new Guid("7c18db98-3c34-4382-963c-1175f0d20f44"), "Happy Valley Medical Clinic (Mck)", "10.24.52.25", "", 1945, "Medisoft", out strApiKey, out strPin);

            //SuperBillLoadingSavingDebugStep();
        }

        private static void SuperBillLoadingSavingDebugStep()
        {
            //string path = Path.GetTempPath();
            //string str = "<Name>Default</Name><Sections><SuperbillSection><Title>Office Visit (New)</Title><BgColor><Red>0</Red><Green>0</Green><Blue>0</Blue></BgColor><Sequence>1</Sequence><Row>0</Row><Column>0</Column><Fields><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>1</Sequence><Code>99201</Code><DisplayText>Problem focused</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>2</Sequence><Code>99202</Code><DisplayText>Expanded problem focused</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>3</Sequence><Code>99203</Code><DisplayText>Detailed</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>4</Sequence><Code>99204</Code><DisplayText>Comprehensive</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>5</Sequence><Code>99205</Code><DisplayText>Comprehensive (new patient)</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>6</Sequence><Code>-25</Code><DisplayText>Significant, separate service</DisplayText><Modifiers /><Units>0</Units></SuperbillField></Fields></SuperbillSection><SuperbillSection><Title>Office Visit (Est)</Title><BgColor><Red>0</Red><Green>0</Green><Blue>0</Blue></BgColor><Sequence>2</Sequence><Row>1</Row><Column>0</Column><Fields><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>1</Sequence><Code>99211</Code><DisplayText>Minimal</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>2</Sequence><Code>99212</Code><DisplayText>Expanded problem focused</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>3</Sequence><Code>99213</Code><DisplayText>Detailed</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>4</Sequence><Code>99214</Code><DisplayText>Comprehensive</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>5</Sequence><Code>99215</Code><DisplayText>Comprehensive (new patient)</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>6</Sequence><Code>-25</Code><DisplayText>Significant, separate service</DisplayText><Modifiers /><Units>0</Units></SuperbillField></Fields></SuperbillSection><SuperbillSection><Title>Discharge Instructions</Title><BgColor><Red>0</Red><Green>0</Green><Blue>0</Blue></BgColor><Sequence>3</Sequence><Row>2</Row><Column>0</Column><Fields><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>1</Sequence><Code /><DisplayText>Comeback in 2 weeks</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>1</Sequence><Code /><DisplayText>Comeback in 4 weeks</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>1</Sequence><Code /><DisplayText>Comeback in 6 weeks</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>1</Sequence><Code /><DisplayText>Comeback in 8 weeks</DisplayText><Modifiers /><Units>0</Units></SuperbillField><SuperbillField><FieldType>Diagnosis</FieldType><Sequence>1</Sequence><Code /><DisplayText>Comeback in 6 months</DisplayText><Modifiers /><Units>0</Units></SuperbillField></Fields></SuperbillSection><SuperbillSection><Title>Skin procedures</Title><BgColor><Red>0</Red><Green>0</Green><Blue>0</Blue></BgColor><Sequence>4</Sequence><Row>3</Row><Column>0</Column><Fields /></SuperbillSection><SuperbillSection><Title>Other services</Title><BgColor><Red>0</Red><Green>0</Green><Blue>0</Blue></BgColor><Sequence>5</Sequence><Row>4</Row><Column>0</Column><Fields /></SuperbillSection></Sections>";            
            //string strPath = ProductType.GetProductSpecificSuperBillDirectoryPath("");
            //XmlDocument xmlDocument = new XmlDocument();
            //XmlNode Data = xmlDocument.CreateNode(XmlNodeType.Element, "SuperBillTemplate", "SuperBillTemplate");
            //Data.InnerXml = str;
            //XmlNode oNode = xmlDocument.ImportNode(Data, true);
            //xmlDocument.AppendChild(oNode);
            //xmlDocument.Save(strPath + "\\" + "Default" + ".msb");            
            //xmlDocument.Load(strPath + "\\" + "Default" + ".msb");
            //XmlNode oNode2 = (XmlNode) xmlDocument;
        }

    }
}
