using System.Diagnostics;
using System.Net;
using System.Text;
using System.Text.Json;
using TaxProEInvoice.API;


namespace TaxProEInvEWBDemo.Net
{
    public partial class Form1 : Form
    {
        public static HttpClient client = new HttpClient();
        public const string AppJsonMediaType = "application/json";
        string WorkingFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        //====================== NOTE ON WORKING OF EInvSession AND IT'S DEFAULT PARAMATERS  ============================================
        //EWBSession object has two main settings objects EwbApiSetting and EwbApiLoginDetails, and some more public properties
        //Default constructor of EWBSession uses json config files to store EwbApiSeting and EwbApiLoginDetails
        //EWBSession constructor has 2 paramaters viz.LoadAPISettingsFromConfigFile and LoadAPILoginDetailsFromConfigFile with default value as True.
        //Thus paramaterless constructor below assums that ASP wants to use config file to store EwbApiSetting and EWBApiLoginDetails
        //in default case, the TaxProEWB.API library will take case of storing AuthToken and Expiary of authtoken internally in json config file.
        //Getting AuthToken if null or expired and storing in EwbApiLoginDetails is concealed calls handled by library.
        //In case ASP needs to change store for EwbApiSetting and EwbApiLoginDetails, pleae refer to "Handling Multiple Taxpayers" section of eWay Bill API Users Guide
        //Also, this demo project contains complete code showing how to create TaxPayer specific EWBSession object using TaxPayer Dependency Injection.




        public eInvoiceSession eInvSession = new eInvoiceSession(true, true, false);
        //public eInvoiceSession eInvSession = new eInvoiceSession(false, false);
        public Form1()
        {
            InitializeComponent();
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            cmbIRPURL.Items.Add(new { Text = "e-Inv1 Portal", Value = 1 });
            cmbIRPURL.Items.Add(new { Text = "e-Inv2 Portal", Value = 2 });
            if (eInvSession.eInvApiLoginDetails.IRPURL == 1)
                cmbIRPURL.SelectedIndex = 0;
            else
                cmbIRPURL.SelectedIndex = 1;

            cmbIRP.Items.Add(new { Text = "IRP-1", Value = 1 });
            cmbIRP.Items.Add(new { Text = "IRP-2", Value = 2 });
            if(eInvSession.eInvApiLoginDetails.IRP == 1)
                cmbIRP.SelectedIndex = 0;
            else
                cmbIRP.SelectedIndex = 1;

            
            loadApiSetting();
            DisplayEInvLoginDetail(cmbIRPURL.SelectedIndex);
            eInvSession.RefreshAuthTokenCompleted += RefreshEinvLoginDetailsDisplay;
            //this code is to display ApiLoginDetails when event refresh auth token get completed
            //EwbSession.RefreshAuthTokenCompleted += RefreshEWBLoginDetailsDisplay;
            eInvSession.SelIrpChanged += SelectedIPRChanged;

        }

        private void SelectedIPRChanged(object? sender, SelIrpChangedEventArg e)
        {
            //Load LoginDetails for e.SelIrp  in eInvSession.
            DisplayEInvLoginDetail(e.SelIrp);

        }

        public void loadApiSetting()
        {
            txtGspName.Text = eInvSession.eInvApiSetting.GSPName;
            txtAspUserId.Text = eInvSession.eInvApiSetting.AspUserId;
            txtAspPassword.Text = eInvSession.eInvApiSetting.AspPassword;
            txtClientId.Text = eInvSession.eInvApiSetting.client_id;
            txtClientSecret.Text = eInvSession.eInvApiSetting.client_secret;
            txtAuthUrl.Text = eInvSession.eInvApiSetting.AuthUrl;
            txtBaseUrl.Text = eInvSession.eInvApiSetting.BaseUrl;
            txtEwbBaseUrl.Text = eInvSession.eInvApiSetting.EwbByIRN;
            txtCancelEWB.Text = eInvSession.eInvApiSetting.CancelEwbUrl;
        }
        //public void loadApiLoginDetail()
        //{
        //    //cmbIRP.SelectedIndex = 0;
        //    txtUserName.Text = eInvSession.eInvApiLoginDetails.UserName;
        //    txtPassword.Text = eInvSession.eInvApiLoginDetails.Password;
        //    txtGSTIN.Text = eInvSession.eInvApiLoginDetails.GSTIN;
        //    txtAppKey.Text = eInvSession.eInvApiLoginDetails.AppKey;
        //    txtAuthToken.Text = eInvSession.eInvApiLoginDetails.AuthToken;
        //    txtSEK.Text = eInvSession.eInvApiLoginDetails.Sek;
        //    txtTokenExp.Text = eInvSession.eInvApiLoginDetails.E_InvoiceTokenExp?.ToString("yyyy-MM-dd HH:mm:ss");
        //}
       
        private void RefreshEinvLoginDetailsDisplay(object sender, AuthTokenEventArg e)
        {
            DisplayEInvLoginDetail(e.SelIrp);
        }
        private void DisplayEInvLoginDetail(int SelIRP)
        {
            if (eInvSession.eInvApiLoginDetails.IRPURL == 1)
                cmbIRPURL.SelectedIndex = 0;
            else
                cmbIRPURL.SelectedIndex = 1;
            txtUserName.Text = eInvSession.eInvApiLoginDetails.UserName;
            txtPassword.Text = eInvSession.eInvApiLoginDetails.Password;
            txtGSTIN.Text = eInvSession.eInvApiLoginDetails.GSTIN;
            txtAppKey.Text = eInvSession.eInvApiLoginDetails.AppKey;
            txtAuthToken.Text = eInvSession.eInvApiLoginDetails.AuthToken;
            txtSEK.Text = eInvSession.eInvApiLoginDetails.Sek;
            txtTokenExp.Text = eInvSession.eInvApiLoginDetails.E_InvoiceTokenExp.ToString();
        }

        private void btnSaveApiSetting_Click(object sender, EventArgs e)
        {

            //Save Einvoive Session
            eInvSession.eInvApiSetting = new eInvoiceAPISetting();
            eInvSession.eInvApiSetting.GSPName = txtGspName.Text;
            eInvSession.eInvApiSetting.AspUserId = txtAspUserId.Text;
            eInvSession.eInvApiSetting.AspPassword = txtAspPassword.Text;
            eInvSession.eInvApiSetting.client_id = txtClientId.Text;
            eInvSession.eInvApiSetting.client_secret = txtClientSecret.Text;
            eInvSession.eInvApiSetting.AuthUrl = txtAuthUrl.Text;
            eInvSession.eInvApiSetting.BaseUrl = txtBaseUrl.Text;
            eInvSession.eInvApiSetting.EwbByIRN = txtEwbBaseUrl.Text;
            eInvSession.eInvApiSetting.CancelEwbUrl = txtCancelEWB.Text;
            TaxProEInvoice.API.Shared.SaveAPISetting(false, eInvSession.eInvApiSetting);
            MessageBox.Show("EInvoice API Setting saved successfully...");
        }

        private void btnSaveLoginDetail_Click(object sender, EventArgs e)
        {
                       //Save Einvoice Login Detail
            eInvSession.eInvApiLoginDetails = new eInvoiceAPILoginDetails();
            eInvSession.eInvApiLoginDetails.UserName = txtUserName.Text;
            eInvSession.eInvApiLoginDetails.Password = txtPassword.Text;
            eInvSession.eInvApiLoginDetails.GSTIN = txtGSTIN.Text;
            eInvSession.eInvApiLoginDetails.AppKey = txtAppKey.Text;
            eInvSession.eInvApiLoginDetails.AuthToken = eInvSession.eInvApiLoginDetails.AuthToken;
            eInvSession.eInvApiLoginDetails.Sek = eInvSession.eInvApiLoginDetails.Sek;
            eInvSession.eInvApiLoginDetails.E_InvoiceTokenExp = eInvSession.eInvApiLoginDetails.E_InvoiceTokenExp;
            eInvSession.eInvApiLoginDetails.IRP = (cmbIRP.SelectedItem as dynamic).Value;
            eInvSession.eInvApiLoginDetails.IRPURL = (cmbIRPURL.SelectedItem as dynamic).Value;
            TaxProEInvoice.API.Shared.SaveAPILoginDetails(false, eInvSession.eInvApiLoginDetails);
            MessageBox.Show("API Login Details saved successfully...");
        }

        //private void button3_Click(object sender, EventArgs e)
        //{
        //    txtGspName.Text = "TaxPro_Sandbox";
        //    txtAuthURL.Text = "http://gstsandbox.charteredinfo.com/eivital/v1.04";
        //    txtBaseUrl.Text = "http://gstsandbox.charteredinfo.com/eicore/v1.03";
        //    txtEwbBaseUrl.Text = "http://gstsandbox.charteredinfo.com/eiewb/v1.03";
        //    txtCancelEWB.Text = "http://gstsandbox.charteredinfo.com/v1.03";
        //    txtUserName.Text = "TaxProEnvPON";
        //    txtPassword.Text = "abc34*";
        //    txtGstin.Text = "34AACCC1596Q002";
        //}

        private async void btnGetAuthToken_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Calling any API method will internally check for valid AuthToken and would try to obtain AuthToken if its is expired.  You don't need to explicitly call GetAuthTokenAsync method. Do you want to proceed?", "AuthToken is Automatic", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                TaxProEInvoice.API.TxnRespWithObj<eInvoiceSession> txnRespWithObj = await eInvoiceAPI.GetAuthTokenAsync(eInvSession);
                if (txnRespWithObj.IsSuccess)
                {
                    //DisplayEInvLoginDetail();
                    //rtbResponce.Text = JsonConvert.SerializeObject(rtbResponce.Text);
                }
                txtHeader.Text = "Auth Api Responce";
                txtResponce.Text = txnRespWithObj.TxnOutcome;
            }
        }

        //private void button4_Click(object sender, EventArgs e)
        //{

        //}

        private void btnEWBSandBoxSetting_Click(object sender, EventArgs e)
        {
            txtGspName.Text = "TaxPro_Sandbox";
            //txtEWBBaseUrl.Text = "http://gstsandbox.charteredinfo.com/ewaybillapi/v1.03";
            txtUserName.Text = "TaxProEnvPON";
            txtPassword.Text = "abc34*";
            txtGSTIN.Text = "34AACCC1596Q002";
        }

        private void btnEInvoiceSandBoxSetting_Click(object sender, EventArgs e)
        {
            txtGspName.Text = "TaxPro_Sandbox";
            txtAuthUrl.Text = "http://gstsandbox.charteredinfo.com/eivital/v1.04";
            txtBaseUrl.Text = "http://gstsandbox.charteredinfo.com/eicore/v1.03";
            //txtEWBUrl.Text = "http://gstsandbox.charteredinfo.com/eiewb/v1.03";
            txtCancelEWB.Text = "http://gstsandbox.charteredinfo.com/v1.03";
            txtUserName.Text = "TaxProEnvPON";
            txtPassword.Text = "abc34*";
            txtGSTIN.Text = "34AACCC1596Q002";
        }
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            int size = -1;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
            if (result == DialogResult.OK) // Test result.
            {
                string file = openFileDialog1.FileName;
                txtHeader.Text = file;

                try
                {
                    txtResponce.Text = File.ReadAllText(file);
                    //size = text.Length;
                }
                catch (IOException)
                {
                }
            }
        }

        private async void btnGenerateIRN_Click(object sender, EventArgs e)
        {
            TaxProEInvoice.API.TxnRespWithObj<RespPlGenIRN> txnRespWithObj = await eInvoiceAPI.GenIRNAsync(eInvSession, txtResponce.Text, 250);

            RespPlGenIRN respPlGenIRN = txnRespWithObj.RespObj;
            string ErrorCodes = "";
            string ErrorDesc = "";
            txtResponce.Text = "";
            if (txnRespWithObj.IsSuccess)
            {
                //Process the Response here
                //For DEMO, just showing the searilized Response Object in text box
                //txtResponce.Text = JsonSerializer.Serialize(respPlGenIRN);
                txtResponce.Text = respPlGenIRN.Irn;
                //respPlGenIRN.QrCodeImage.Save(@"C:\Users\Desktop\qr1.png");

                //Store respPlGenIRN (manditory - AckDate and SignedInvoice) to verify signed invoice
                //below code is to show how to verify signed invoice
                //respPlGenIRN.QrCodeImage = null;
                //TaxProEInvoice.API.TxnRespWithObj<VerifyRespPl> txnRespWithObj1 = await eInvoiceAPI.VerifySignedInvoice(eInvSession, respPlGenIRN);


                //VerifyRespPl verifyRespPl = new VerifyRespPl();
                //if (txnRespWithObj.IsSuccess)
                //{
                //    verifyRespPl.IsVerified = txnRespWithObj1.RespObj.IsVerified;
                //    verifyRespPl.JwtIssuerIRP = txnRespWithObj1.RespObj.JwtIssuerIRP;
                //    verifyRespPl.VerifiedWithCertificateEffectiveFrom = txnRespWithObj1.RespObj.VerifiedWithCertificateEffectiveFrom;
                //    verifyRespPl.CertificateName = txnRespWithObj1.RespObj.CertificateName;
                //    verifyRespPl.CertStartDate = txnRespWithObj1.RespObj.CertStartDate;
                //    verifyRespPl.CertExpiryDate = txnRespWithObj1.RespObj.CertExpiryDate;
                //}

            }
            else
            {
                //Error has occured
                //Display TxnOutCome in text box - process or show msg to user

                //Process error codes
                if (txnRespWithObj.ErrorDetails != null)
                {
                    foreach (TaxProEInvoice.API.RespErrDetailsPl errPl in txnRespWithObj.ErrorDetails)
                    {
                        //Process errPl item here
                        ErrorCodes += errPl.ErrorCode + ",";
                        ErrorDesc += errPl.ErrorCode + ": " + errPl.ErrorMessage + Environment.NewLine;
                        txtResponce.Text = ErrorDesc;
                    }
                }

                //Process InfoDetails here
                TaxProEInvoice.API.RespInfoDtlsPl respInfoDtlsPl = new TaxProEInvoice.API.RespInfoDtlsPl();
                //Serialize Desc object from InfoDtls as per InfCd
                if (txnRespWithObj.InfoDetails != null)
                {
                    foreach (TaxProEInvoice.API.RespInfoDtlsPl infoPl in txnRespWithObj.InfoDetails)
                    {
                        var strDupIrnPl = JsonSerializer.Serialize(infoPl.Desc);   //Convert object type to json string
                        switch (infoPl.InfCd)
                        {
                            case "DUPIRN":
                                DupIrnPl dupIrnPl = JsonSerializer.Deserialize<DupIrnPl>(strDupIrnPl);
                                break;
                            case "EWBERR":
                                List<EwbErrPl> ewbErrPl = JsonSerializer.Deserialize<List<EwbErrPl>>(strDupIrnPl);
                                break;
                            case "ADDNLNFO":
                                //Deserialize infoPl.Desc as string type and then if this string contains json object, it may be desirilized again as per future releases
                                string strDesc = (string)infoPl.Desc;
                                break;
                        }
                    }
                }
            }//else end
            txtHeader.Text = "Generate IRN Responce...";
        }

        private async void btnVerifiSignedInv_Click(object sender, EventArgs e)
        {
            string RespJson = File.ReadAllText(WorkingFilesPath + @"\RespPlGenIRN.txt");
            VerifyRespPl verifyRespPl = new VerifyRespPl();

            RespPlGenIRN respPlGenIRN = new RespPlGenIRN();
            respPlGenIRN = JsonSerializer.Deserialize<RespPlGenIRN>(RespJson);
            TaxProEInvoice.API.TxnRespWithObj<VerifyRespPl> txnRespWithObj = await eInvoiceAPI.VerifySignedInvoice(eInvSession, respPlGenIRN);

            if (txnRespWithObj.IsSuccess)
            {
                verifyRespPl.IsVerified = txnRespWithObj.RespObj.IsVerified;
                verifyRespPl.JwtIssuerIRP = txnRespWithObj.RespObj.JwtIssuerIRP;
                verifyRespPl.VerifiedWithCertificateEffectiveFrom = txnRespWithObj.RespObj.VerifiedWithCertificateEffectiveFrom;
                verifyRespPl.CertificateName = txnRespWithObj.RespObj.CertificateName;
                verifyRespPl.CertStartDate = txnRespWithObj.RespObj.CertStartDate;
                verifyRespPl.CertExpiryDate = txnRespWithObj.RespObj.CertExpiryDate;
            }
            else
            {
                verifyRespPl = txnRespWithObj.RespObj;

            }
        }

        private async void btnCancelIRN_Click(object sender, EventArgs e)
        {
            ReqPlCancelIRN reqPlCancelIRN = new ReqPlCancelIRN();
            reqPlCancelIRN.CnlRem = "Data Entry Mystake";
            reqPlCancelIRN.CnlRsn = "2";
            reqPlCancelIRN.Irn = "ce02d2cb142f170fe5c14a045838a26502bdf1f58f6ecfaf5fddf93855bcde76";
            TaxProEInvoice.API.TxnRespWithObj<RespPlCancelIRN> txnRespWithObj = await eInvoiceAPI.CancelIRNIRNAsync(eInvSession, reqPlCancelIRN);

            if (txnRespWithObj.IsSuccess)
            {
                txtResponce.Text = JsonSerializer.Serialize(txnRespWithObj.RespObj);
            }
            else
                txtResponce.Text = txnRespWithObj.TxnOutcome;

            txtHeader.Text = "Generate IRN Responce...";
        }

        private async void btnGetInvDetailByIRN_Click(object sender, EventArgs e)
        {
            string IrnNo = "bb35b2761746f1e178c5b94637a75ec5e06fa1eb66113966e730f1fdfb08d30c";
            TaxProEInvoice.API.TxnRespWithObj<RespPlGenIRN> txnRespWithObj = await eInvoiceAPI.GetEInvDetailsAsync(eInvSession, IrnNo);
            if (txnRespWithObj.IsSuccess)
            {
                txtResponce.Text = JsonSerializer.Serialize(txnRespWithObj.RespObj);
            }
            else
                txtResponce.Text = txnRespWithObj.TxnOutcome;
            txtHeader.Text = "Get IRN Detail Responce...";
        }

        private void btnGetInvDetailsbyAck_Click(object sender, EventArgs e)
        {

        }

        private async void btnGenEwbByIRN_Click(object sender, EventArgs e)
        {
            //Generate Ewb By IRN
            ReqPlGenEwbByIRN reqPlGenEwbByIRN = new ReqPlGenEwbByIRN();
            reqPlGenEwbByIRN.Irn = "bb35b2761746f1e178c5b94637a75ec5e06fa1eb66113966e730f1fdfb08d30c";
            reqPlGenEwbByIRN.TransId = "27AACFM5833D1ZH";//12AWGPV7107B1Z1
            reqPlGenEwbByIRN.TransMode = "3";
            reqPlGenEwbByIRN.TransDocNo = "DOC7";
            reqPlGenEwbByIRN.TransDocDt = "06/01/2023";//
            reqPlGenEwbByIRN.VehNo = "ka123458";// 
            reqPlGenEwbByIRN.Distance = 0;
            reqPlGenEwbByIRN.VehType = "R";//R
            reqPlGenEwbByIRN.TransName = "DFHGF";
            reqPlGenEwbByIRN.ExpShipDtls = new ExportShipDetails();
            reqPlGenEwbByIRN.ExpShipDtls.Addr1 = "7th block, kuvempu layout";
            reqPlGenEwbByIRN.ExpShipDtls.Addr2 = "kuvempu layout";
            reqPlGenEwbByIRN.ExpShipDtls.Loc = "Banagalore";
            reqPlGenEwbByIRN.ExpShipDtls.Pin = 562160;
            reqPlGenEwbByIRN.ExpShipDtls.Stcd = "29";
            reqPlGenEwbByIRN.DispDtls = new DispatchedDetails();
            reqPlGenEwbByIRN.DispDtls.Nm = "ABC company pvt ltd";
            reqPlGenEwbByIRN.DispDtls.Addr1 = "7th block, kuvempu layout";
            reqPlGenEwbByIRN.DispDtls.Addr2 = "kuvempu layout";
            reqPlGenEwbByIRN.DispDtls.Loc = "Banagalore";
            reqPlGenEwbByIRN.DispDtls.Pin = 562160;
            reqPlGenEwbByIRN.DispDtls.Stcd = "29";

            TaxProEInvoice.API.TxnRespWithObj<RespPlGenEwbByIRN> txnRespWithObj = await eInvoiceAPI.GenEwbByIRNAsync(eInvSession, reqPlGenEwbByIRN);
            string ErrorCodes = "";
            string ErrorDesc = "";
            txtResponce.Text = "";
            if (txnRespWithObj.IsSuccess)
            {
                txtResponce.Text = JsonSerializer.Serialize(txnRespWithObj.RespObj);
            }
            else
            {
                // rtbResponce.Text = txnRespWithObj.TxnOutcome;
                if (txnRespWithObj.ErrorDetails != null)
                {
                    foreach (TaxProEInvoice.API.RespErrDetailsPl errPl in txnRespWithObj.ErrorDetails)
                    {
                        //Process errPl item here
                        ErrorCodes += errPl.ErrorCode + ",";
                        ErrorDesc += errPl.ErrorCode + ": " + errPl.ErrorMessage + Environment.NewLine;
                        txtResponce.Text = ErrorDesc;
                    }
                }
            }


            txtHeader.Text = "Generate IRN Responce...";

        }

        private async void btnGetGstinDetail_Click(object sender, EventArgs e)
        {
            string GSTIN = "34AACCC1596Q002";
            TaxProEInvoice.API.TxnRespWithObj<RespPlGetGSTIN> txnRespWithObj = await eInvoiceAPI.GetGSTINDetailsAsync(eInvSession, GSTIN);
            if (txnRespWithObj.IsSuccess)
            {
                txtResponce.Text = JsonSerializer.Serialize(txnRespWithObj.RespObj);
            }
            else
                txtResponce.Text = txnRespWithObj.TxnOutcome;

            txtHeader.Text = "Get GSTIN Detail Responce...";
        }

        private async void btnSyncGstinDet_Click(object sender, EventArgs e)
        {
            {
                string GSTIN = "33GSPTN1882G1Z3";
                TaxProEInvoice.API.TxnRespWithObj<RespPlGetGSTIN> txnRespWithObj = await eInvoiceAPI.SyncGSTINAsync(eInvSession, GSTIN);
                if (txnRespWithObj.IsSuccess)
                {
                    txtResponce.Text = JsonSerializer.Serialize(txnRespWithObj.RespObj);
                }
                else
                    txtResponce.Text = txnRespWithObj.TxnOutcome;

                txtHeader.Text = "Get Sync GSTIN Detail Responce...";
            }
        }

        private async void btnCancelEWB_Click(object sender, EventArgs e)
        {
            string action = "CANEWB";
            ReqPlCancelEWB reqPlCancelEWB = new ReqPlCancelEWB();
            reqPlCancelEWB.ewbNo = 681302083122;
            reqPlCancelEWB.cancelRsnCode = 2;
            reqPlCancelEWB.cancelRmrk = "Cancelled the order";
            TaxProEInvoice.API.TxnRespWithObj<RespPlCancelEWB> txnRespWithObj = await eInvoiceAPI.CancelEWBAsync(eInvSession, reqPlCancelEWB, action);

            if (txnRespWithObj.IsSuccess)
            {
                txtResponce.Text = JsonSerializer.Serialize(txnRespWithObj.RespObj);
            }
            else
                txtResponce.Text = txnRespWithObj.TxnOutcome;

            txtHeader.Text = "Generate IRN Responce...";
        }

        private async void btnGetEWBByIRN_Click(object sender, EventArgs e)
        {
            {
                string IRN_No = "bb35b2761746f1e178c5b94637a75ec5e06fa1eb66113966e730f1fdfb08d30c";
                TaxProEInvoice.API.TxnRespWithObj<RespGetEWBByIRN> txnRespWithObj = await eInvoiceAPI.GetEWBByIRNAsync(eInvSession, IRN_No);
                if (txnRespWithObj.IsSuccess)
                {
                    txtResponce.Text = JsonSerializer.Serialize(txnRespWithObj.RespObj);
                }
                else
                    txtResponce.Text = txnRespWithObj.TxnOutcome;

                txtHeader.Text = "Get EWB By IRN Responce...";
            }
        }

        private async void btnGetIRNDetByDoc_Click(object sender, EventArgs e)
        {
            {
                string DocType = "INV";
                string DocNum = "GSP23240146";
                string DocDate = "13/04/2023";

                TaxProEInvoice.API.TxnRespWithObj<RespPlGenIRN> txnRespWithObj = await eInvoiceAPI.GetIRNDetailsByDocDetailsAsync(eInvSession, DocType, DocNum, DocDate, 250);
                if (txnRespWithObj.IsSuccess)
                {
                    txtResponce.Text = JsonSerializer.Serialize(txnRespWithObj.RespObj);
                }
                else
                    txtResponce.Text = txnRespWithObj.TxnOutcome;

                txtHeader.Text = "Get IRN Details By Doc Detail Responce...";
            }

        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void cmbIRP_SelectedIndexChanged(object sender, EventArgs e)
        {
            eInvSession.SelIRP = (cmbIRP.SelectedItem as dynamic).Value;

        }

        private void cmbIRPURL_SelectedIndexChanged(object sender, EventArgs e)
        {
            eInvSession.eInvApiLoginDetails.IRPURL = (cmbIRPURL.SelectedItem as dynamic).Value;
        }
    }
}