/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/core/utils/StringUtils.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
#include <aws/rds/model/RestoreDBClusterToPointInTimeRequest.h>

using namespace Aws::RDS::Model;
using namespace Aws::Utils;

Aws::String RestoreDBClusterToPointInTimeRequest::SerializePayload() const {
  Aws::StringStream ss;
  ss << "Action=RestoreDBClusterToPointInTime&";
  if (m_dBClusterIdentifierHasBeenSet) {
    ss << "DBClusterIdentifier=" << StringUtils::URLEncode(m_dBClusterIdentifier.c_str()) << "&";
  }

  if (m_restoreTypeHasBeenSet) {
    ss << "RestoreType=" << StringUtils::URLEncode(m_restoreType.c_str()) << "&";
  }

  if (m_sourceDBClusterIdentifierHasBeenSet) {
    ss << "SourceDBClusterIdentifier=" << StringUtils::URLEncode(m_sourceDBClusterIdentifier.c_str()) << "&";
  }

  if (m_restoreToTimeHasBeenSet) {
    ss << "RestoreToTime=" << StringUtils::URLEncode(m_restoreToTime.ToGmtString(Aws::Utils::DateFormat::ISO_8601).c_str()) << "&";
  }

  if (m_useLatestRestorableTimeHasBeenSet) {
    ss << "UseLatestRestorableTime=" << std::boolalpha << m_useLatestRestorableTime << "&";
  }

  if (m_portHasBeenSet) {
    ss << "Port=" << m_port << "&";
  }

  if (m_dBSubnetGroupNameHasBeenSet) {
    ss << "DBSubnetGroupName=" << StringUtils::URLEncode(m_dBSubnetGroupName.c_str()) << "&";
  }

  if (m_optionGroupNameHasBeenSet) {
    ss << "OptionGroupName=" << StringUtils::URLEncode(m_optionGroupName.c_str()) << "&";
  }

  if (m_vpcSecurityGroupIdsHasBeenSet) {
    if (m_vpcSecurityGroupIds.empty()) {
      ss << "VpcSecurityGroupIds=&";
    } else {
      unsigned vpcSecurityGroupIdsCount = 1;
      for (auto& item : m_vpcSecurityGroupIds) {
        ss << "VpcSecurityGroupIds.VpcSecurityGroupId." << vpcSecurityGroupIdsCount << "=" << StringUtils::URLEncode(item.c_str()) << "&";
        vpcSecurityGroupIdsCount++;
      }
    }
  }

  if (m_tagsHasBeenSet) {
    if (m_tags.empty()) {
      ss << "Tags=&";
    } else {
      unsigned tagsCount = 1;
      for (auto& item : m_tags) {
        item.OutputToStream(ss, "Tags.Tag.", tagsCount, "");
        tagsCount++;
      }
    }
  }

  if (m_kmsKeyIdHasBeenSet) {
    ss << "KmsKeyId=" << StringUtils::URLEncode(m_kmsKeyId.c_str()) << "&";
  }

  if (m_enableIAMDatabaseAuthenticationHasBeenSet) {
    ss << "EnableIAMDatabaseAuthentication=" << std::boolalpha << m_enableIAMDatabaseAuthentication << "&";
  }

  if (m_backtrackWindowHasBeenSet) {
    ss << "BacktrackWindow=" << m_backtrackWindow << "&";
  }

  if (m_enableCloudwatchLogsExportsHasBeenSet) {
    if (m_enableCloudwatchLogsExports.empty()) {
      ss << "EnableCloudwatchLogsExports=&";
    } else {
      unsigned enableCloudwatchLogsExportsCount = 1;
      for (auto& item : m_enableCloudwatchLogsExports) {
        ss << "EnableCloudwatchLogsExports.member." << enableCloudwatchLogsExportsCount << "=" << StringUtils::URLEncode(item.c_str())
           << "&";
        enableCloudwatchLogsExportsCount++;
      }
    }
  }

  if (m_dBClusterParameterGroupNameHasBeenSet) {
    ss << "DBClusterParameterGroupName=" << StringUtils::URLEncode(m_dBClusterParameterGroupName.c_str()) << "&";
  }

  if (m_deletionProtectionHasBeenSet) {
    ss << "DeletionProtection=" << std::boolalpha << m_deletionProtection << "&";
  }

  if (m_copyTagsToSnapshotHasBeenSet) {
    ss << "CopyTagsToSnapshot=" << std::boolalpha << m_copyTagsToSnapshot << "&";
  }

  if (m_domainHasBeenSet) {
    ss << "Domain=" << StringUtils::URLEncode(m_domain.c_str()) << "&";
  }

  if (m_domainIAMRoleNameHasBeenSet) {
    ss << "DomainIAMRoleName=" << StringUtils::URLEncode(m_domainIAMRoleName.c_str()) << "&";
  }

  if (m_dBClusterInstanceClassHasBeenSet) {
    ss << "DBClusterInstanceClass=" << StringUtils::URLEncode(m_dBClusterInstanceClass.c_str()) << "&";
  }

  if (m_storageTypeHasBeenSet) {
    ss << "StorageType=" << StringUtils::URLEncode(m_storageType.c_str()) << "&";
  }

  if (m_publiclyAccessibleHasBeenSet) {
    ss << "PubliclyAccessible=" << std::boolalpha << m_publiclyAccessible << "&";
  }

  if (m_iopsHasBeenSet) {
    ss << "Iops=" << m_iops << "&";
  }

  if (m_networkTypeHasBeenSet) {
    ss << "NetworkType=" << StringUtils::URLEncode(m_networkType.c_str()) << "&";
  }

  if (m_sourceDbClusterResourceIdHasBeenSet) {
    ss << "SourceDbClusterResourceId=" << StringUtils::URLEncode(m_sourceDbClusterResourceId.c_str()) << "&";
  }

  if (m_serverlessV2ScalingConfigurationHasBeenSet) {
    m_serverlessV2ScalingConfiguration.OutputToStream(ss, "ServerlessV2ScalingConfiguration");
  }

  if (m_scalingConfigurationHasBeenSet) {
    m_scalingConfiguration.OutputToStream(ss, "ScalingConfiguration");
  }

  if (m_engineModeHasBeenSet) {
    ss << "EngineMode=" << StringUtils::URLEncode(m_engineMode.c_str()) << "&";
  }

  if (m_rdsCustomClusterConfigurationHasBeenSet) {
    m_rdsCustomClusterConfiguration.OutputToStream(ss, "RdsCustomClusterConfiguration");
  }

  if (m_monitoringIntervalHasBeenSet) {
    ss << "MonitoringInterval=" << m_monitoringInterval << "&";
  }

  if (m_monitoringRoleArnHasBeenSet) {
    ss << "MonitoringRoleArn=" << StringUtils::URLEncode(m_monitoringRoleArn.c_str()) << "&";
  }

  if (m_enablePerformanceInsightsHasBeenSet) {
    ss << "EnablePerformanceInsights=" << std::boolalpha << m_enablePerformanceInsights << "&";
  }

  if (m_performanceInsightsKMSKeyIdHasBeenSet) {
    ss << "PerformanceInsightsKMSKeyId=" << StringUtils::URLEncode(m_performanceInsightsKMSKeyId.c_str()) << "&";
  }

  if (m_performanceInsightsRetentionPeriodHasBeenSet) {
    ss << "PerformanceInsightsRetentionPeriod=" << m_performanceInsightsRetentionPeriod << "&";
  }

  if (m_backupRetentionPeriodHasBeenSet) {
    ss << "BackupRetentionPeriod=" << m_backupRetentionPeriod << "&";
  }

  if (m_preferredBackupWindowHasBeenSet) {
    ss << "PreferredBackupWindow=" << StringUtils::URLEncode(m_preferredBackupWindow.c_str()) << "&";
  }

  if (m_engineLifecycleSupportHasBeenSet) {
    ss << "EngineLifecycleSupport=" << StringUtils::URLEncode(m_engineLifecycleSupport.c_str()) << "&";
  }

  if (m_tagSpecificationsHasBeenSet) {
    if (m_tagSpecifications.empty()) {
      ss << "TagSpecifications=&";
    } else {
      unsigned tagSpecificationsCount = 1;
      for (auto& item : m_tagSpecifications) {
        item.OutputToStream(ss, "TagSpecifications.item.", tagSpecificationsCount, "");
        tagSpecificationsCount++;
      }
    }
  }

  if (m_enableVPCNetworkingHasBeenSet) {
    ss << "EnableVPCNetworking=" << std::boolalpha << m_enableVPCNetworking << "&";
  }

  if (m_enableInternetAccessGatewayHasBeenSet) {
    ss << "EnableInternetAccessGateway=" << std::boolalpha << m_enableInternetAccessGateway << "&";
  }

  ss << "Version=2014-10-31";
  return ss.str();
}

void RestoreDBClusterToPointInTimeRequest::DumpBodyToUrl(Aws::Http::URI& uri) const { uri.SetQueryString(SerializePayload()); }
