public override string ToCSharp(List <string> definedVariables, ConfigSettings settings)
        {
            using var writer = new StringWriter();
            writer.Write("await ");

            switch (RequestParams)
            {
            case StandardRequestParams x:
                writer.Write("HttpRequestStandard(data, new StandardHttpRequestOptions { ");
                writer.Write("Content = " + CSharpWriter.FromSetting(x.Content) + ", ");
                writer.Write("ContentType = " + CSharpWriter.FromSetting(x.ContentType) + ", ");
                writer.Write("UrlEncodeContent = " + GetSettingValue("urlEncodeContent") + ", ");
                break;

            case RawRequestParams x:
                writer.Write("HttpRequestRaw(data, new RawHttpRequestOptions { ");
                writer.Write("Content = " + CSharpWriter.FromSetting(x.Content) + ", ");
                writer.Write("ContentType = " + CSharpWriter.FromSetting(x.ContentType) + ", ");
                break;

            case BasicAuthRequestParams x:
                writer.Write("HttpRequestBasicAuth(data, new BasicAuthHttpRequestOptions { ");
                writer.Write("Username = "******", ");
                writer.Write("Password = "******", ");
                break;

            case MultipartRequestParams x:
                writer.Write("HttpRequestMultipart(data, new MultipartHttpRequestOptions { ");
                writer.Write("Boundary = " + CSharpWriter.FromSetting(x.Boundary) + ", ");
                writer.Write("Contents = " + SerializeMultipart(x.Contents) + ", ");
                break;
            }

            writer.Write("Url = " + GetSettingValue("url") + ", ");
            writer.Write("Method = " + GetSettingValue("method") + ", ");
            writer.Write("AutoRedirect = " + GetSettingValue("autoRedirect") + ", ");
            writer.Write("MaxNumberOfRedirects = " + GetSettingValue("maxNumberOfRedirects") + ", ");
            writer.Write("ReadResponseContent = " + GetSettingValue("readResponseContent") + ", ");
            writer.Write("AbsoluteUriInFirstLine = " + GetSettingValue("absoluteUriInFirstLine") + ", ");
            writer.Write("SecurityProtocol = " + GetSettingValue("securityProtocol") + ", ");
            writer.Write("CustomCookies = " + GetSettingValue("customCookies") + ", ");
            writer.Write("CustomHeaders = " + GetSettingValue("customHeaders") + ", ");
            writer.Write("TimeoutMilliseconds = " + GetSettingValue("timeoutMilliseconds") + ", ");
            writer.Write("HttpVersion = " + GetSettingValue("httpVersion") + ", ");
            writer.Write("CodePagesEncoding = " + GetSettingValue("codePagesEncoding") + ", ");
            writer.Write("AlwaysSendContent = " + GetSettingValue("alwaysSendContent") + ", ");
            writer.Write("UseCustomCipherSuites = " + GetSettingValue("useCustomCipherSuites") + ", ");
            writer.Write("CustomCipherSuites = " + GetSettingValue("customCipherSuites") + " ");

            writer.WriteLine("}).ConfigureAwait(false);");

            return(writer.ToString());
        }
 private string SerializeContent(HttpContentSettingsGroup content)
 {
     return(content switch
     {
         StringHttpContentSettingsGroup x =>
         $"new StringHttpContent({CSharpWriter.FromSetting(x.Name)}, {CSharpWriter.FromSetting(x.Data)}, {CSharpWriter.FromSetting(x.ContentType)})",
         RawHttpContentSettingsGroup x =>
         $"new RawHttpContent({CSharpWriter.FromSetting(x.Name)}, {CSharpWriter.FromSetting(x.Data)}, {CSharpWriter.FromSetting(x.ContentType)})",
         FileHttpContentSettingsGroup x =>
         $"new FileHttpContent({CSharpWriter.FromSetting(x.Name)}, {CSharpWriter.FromSetting(x.FileName)}, {CSharpWriter.FromSetting(x.ContentType)})",
         _ => throw new NotImplementedException()
     });
        public override string ToCSharp(List <string> definedVariables, ConfigSettings settings)
        {
            /*
             *   if (Conditions.Check(myVar, StrComparison.Contains, "hello"))
             *     data.STATUS = "SUCCESS";
             *
             *   else if (Conditions.Check(myList, ListComparison.Contains, "item") || Conditions.Check(data.COOKIES, DictComparison.HasKey, "name"))
             *     { data.STATUS = "FAIL"; return; }
             *
             *   else if (myBool)
             *     { data.STATUS = "BAN"; return; }
             */

            using var writer = new StringWriter();
            var banIfNoMatch = Settings["banIfNoMatch"];
            var nonEmpty     = Keychains.Where(kc => kc.Keys.Count > 0).ToList();

            // If there are no keychains
            if (nonEmpty.Count == 0)
            {
                writer.WriteLine($"if ({CSharpWriter.FromSetting(banIfNoMatch)})");

                if (settings.GeneralSettings.ContinueStatuses.Contains("BAN"))
                {
                    writer.WriteLine(" { data.STATUS = \"BAN\"; }");
                    writer.WriteLine("if (CheckGlobalBanKeys(data)) { data.STATUS = \"BAN\"; }");
                }
                else
                {
                    writer.WriteLine("  { data.STATUS = \"BAN\"; return; }");
                    writer.WriteLine("if (CheckGlobalBanKeys(data)) { data.STATUS = \"BAN\"; return; }");
                }

                if (settings.GeneralSettings.ContinueStatuses.Contains("RETRY"))
                {
                    writer.WriteLine("if (CheckGlobalRetryKeys(data)) { data.STATUS = \"RETRY\"; }");
                }
                else
                {
                    writer.WriteLine("if (CheckGlobalRetryKeys(data)) { data.STATUS = \"RETRY\"; return; }");
                }

                return(writer.ToString());
            }

            // Write all the keychains
            for (var i = 0; i < nonEmpty.Count; i++)
            {
                var keychain = nonEmpty[i];

                if (i == 0)
                {
                    writer.Write("if (");
                }
                else
                {
                    writer.Write("else if (");
                }

                var conditions = keychain.Keys.Select(k => CSharpWriter.ConvertKey(k));

                var chainedCondition = keychain.Mode switch
                {
                    KeychainMode.OR => string.Join(" || ", conditions),
                    KeychainMode.AND => string.Join(" && ", conditions),
                    _ => throw new Exception("Invalid Keychain Mode")
                };

                writer.Write(chainedCondition);
                writer.WriteLine(")");

                // Continue on this status
                if (settings.GeneralSettings.ContinueStatuses.Contains(keychain.ResultStatus))
                {
                    writer.WriteLine($" {{ data.STATUS = \"{keychain.ResultStatus}\"; }}");
                }

                // Do not continue on this status (return)
                else
                {
                    writer.WriteLine($"  {{ data.STATUS = \"{keychain.ResultStatus}\"; return; }}");
                }
            }

            // The whole purpose of this is to make the code a bit prettier
            if (banIfNoMatch.InputMode == SettingInputMode.Fixed)
            {
                if (((BoolSetting)banIfNoMatch.FixedSetting).Value)
                {
                    writer.WriteLine("else");

                    if (settings.GeneralSettings.ContinueStatuses.Contains("BAN"))
                    {
                        writer.WriteLine(" { data.STATUS = \"BAN\"; }");
                    }
                    else
                    {
                        writer.WriteLine("  { data.STATUS = \"BAN\"; return; }");
                    }
                }
                else
                {
                }
            }
            else
            {
                writer.WriteLine($"else if ({CSharpWriter.FromSetting(banIfNoMatch)})");

                if (settings.GeneralSettings.ContinueStatuses.Contains("BAN"))
                {
                    writer.WriteLine(" { data.STATUS = \"BAN\"; }");
                }
                else
                {
                    writer.WriteLine("  { data.STATUS = \"BAN\"; return; }");
                }
            }

            // Check global ban keys
            if (settings.GeneralSettings.ContinueStatuses.Contains("BAN"))
            {
                writer.WriteLine("if (CheckGlobalBanKeys(data)) { data.STATUS = \"BAN\"; }");
            }
            else
            {
                writer.WriteLine("if (CheckGlobalBanKeys(data)) { data.STATUS = \"BAN\"; return; }");
            }

            if (settings.GeneralSettings.ContinueStatuses.Contains("RETRY"))
            {
                writer.WriteLine("if (CheckGlobalRetryKeys(data)) { data.STATUS = \"RETRY\"; }");
            }
            else
            {
                writer.WriteLine("if (CheckGlobalRetryKeys(data)) { data.STATUS = \"RETRY\"; return; }");
            }

            return(writer.ToString());
        }
    }