import {
  AWSClient,
  buildQueryParams
} from "./chunk-zqtpg06c.js";

// src/aws/rds.ts
class RDSClient {
  client;
  region;
  constructor(region = "us-east-1") {
    this.region = region;
    this.client = new AWSClient;
  }
  async describeDBInstances(options) {
    const params = {
      Action: "DescribeDBInstances",
      Version: "2014-10-31"
    };
    if (options?.DBInstanceIdentifier) {
      params.DBInstanceIdentifier = options.DBInstanceIdentifier;
    }
    if (options?.MaxRecords) {
      params.MaxRecords = options.MaxRecords;
    }
    if (options?.Marker) {
      params.Marker = options.Marker;
    }
    if (options?.Filters) {
      options.Filters.forEach((filter, i) => {
        params[`Filters.Filter.${i + 1}.Name`] = filter.Name;
        filter.Values.forEach((value, j) => {
          params[`Filters.Filter.${i + 1}.Values.Value.${j + 1}`] = value;
        });
      });
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.DescribeDBInstancesResult || result;
    let instances = response.DBInstances?.DBInstance || [];
    if (!Array.isArray(instances)) {
      instances = instances ? [instances] : [];
    }
    return {
      DBInstances: instances,
      Marker: response.Marker
    };
  }
  async describeDBInstance(dbInstanceIdentifier) {
    const result = await this.describeDBInstances({
      DBInstanceIdentifier: dbInstanceIdentifier
    });
    return result.DBInstances?.[0];
  }
  async describeDBClusters(options) {
    const params = {
      Action: "DescribeDBClusters",
      Version: "2014-10-31"
    };
    if (options?.DBClusterIdentifier) {
      params.DBClusterIdentifier = options.DBClusterIdentifier;
    }
    if (options?.MaxRecords) {
      params.MaxRecords = options.MaxRecords;
    }
    if (options?.Marker) {
      params.Marker = options.Marker;
    }
    if (options?.Filters) {
      options.Filters.forEach((filter, i) => {
        params[`Filters.Filter.${i + 1}.Name`] = filter.Name;
        filter.Values.forEach((value, j) => {
          params[`Filters.Filter.${i + 1}.Values.Value.${j + 1}`] = value;
        });
      });
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.DescribeDBClustersResult || result;
    let clusters = response.DBClusters?.DBCluster || [];
    if (!Array.isArray(clusters)) {
      clusters = clusters ? [clusters] : [];
    }
    return {
      DBClusters: clusters,
      Marker: response.Marker
    };
  }
  async describeDBSnapshots(options) {
    const params = {
      Action: "DescribeDBSnapshots",
      Version: "2014-10-31"
    };
    if (options?.DBInstanceIdentifier) {
      params.DBInstanceIdentifier = options.DBInstanceIdentifier;
    }
    if (options?.DBSnapshotIdentifier) {
      params.DBSnapshotIdentifier = options.DBSnapshotIdentifier;
    }
    if (options?.SnapshotType) {
      params.SnapshotType = options.SnapshotType;
    }
    if (options?.MaxRecords) {
      params.MaxRecords = options.MaxRecords;
    }
    if (options?.Marker) {
      params.Marker = options.Marker;
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.DescribeDBSnapshotsResult || result;
    let snapshots = response.DBSnapshots?.DBSnapshot || [];
    if (!Array.isArray(snapshots)) {
      snapshots = snapshots ? [snapshots] : [];
    }
    return {
      DBSnapshots: snapshots,
      Marker: response.Marker
    };
  }
  async describeDBSubnetGroups(options) {
    const params = {
      Action: "DescribeDBSubnetGroups",
      Version: "2014-10-31"
    };
    if (options?.DBSubnetGroupName) {
      params.DBSubnetGroupName = options.DBSubnetGroupName;
    }
    if (options?.MaxRecords) {
      params.MaxRecords = options.MaxRecords;
    }
    if (options?.Marker) {
      params.Marker = options.Marker;
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.DescribeDBSubnetGroupsResult || result;
    let groups = response.DBSubnetGroups?.DBSubnetGroup || [];
    if (!Array.isArray(groups)) {
      groups = groups ? [groups] : [];
    }
    return {
      DBSubnetGroups: groups,
      Marker: response.Marker
    };
  }
  async createDBInstance(options) {
    const params = {
      Action: "CreateDBInstance",
      Version: "2014-10-31",
      DBInstanceIdentifier: options.DBInstanceIdentifier,
      DBInstanceClass: options.DBInstanceClass,
      Engine: options.Engine
    };
    if (options.DBClusterIdentifier)
      params.DBClusterIdentifier = options.DBClusterIdentifier;
    if (options.MasterUsername)
      params.MasterUsername = options.MasterUsername;
    if (options.MasterUserPassword)
      params.MasterUserPassword = options.MasterUserPassword;
    if (options.DBName)
      params.DBName = options.DBName;
    if (options.AllocatedStorage)
      params.AllocatedStorage = options.AllocatedStorage;
    if (options.DBSubnetGroupName)
      params.DBSubnetGroupName = options.DBSubnetGroupName;
    if (options.AvailabilityZone)
      params.AvailabilityZone = options.AvailabilityZone;
    if (options.PreferredMaintenanceWindow)
      params.PreferredMaintenanceWindow = options.PreferredMaintenanceWindow;
    if (options.PreferredBackupWindow)
      params.PreferredBackupWindow = options.PreferredBackupWindow;
    if (options.BackupRetentionPeriod !== undefined)
      params.BackupRetentionPeriod = options.BackupRetentionPeriod;
    if (options.MultiAZ !== undefined)
      params.MultiAZ = options.MultiAZ;
    if (options.EngineVersion)
      params.EngineVersion = options.EngineVersion;
    if (options.AutoMinorVersionUpgrade !== undefined)
      params.AutoMinorVersionUpgrade = options.AutoMinorVersionUpgrade;
    if (options.LicenseModel)
      params.LicenseModel = options.LicenseModel;
    if (options.PubliclyAccessible !== undefined)
      params.PubliclyAccessible = options.PubliclyAccessible;
    if (options.StorageType)
      params.StorageType = options.StorageType;
    if (options.StorageEncrypted !== undefined)
      params.StorageEncrypted = options.StorageEncrypted;
    if (options.KmsKeyId)
      params.KmsKeyId = options.KmsKeyId;
    if (options.DeletionProtection !== undefined)
      params.DeletionProtection = options.DeletionProtection;
    if (options.VpcSecurityGroupIds) {
      options.VpcSecurityGroupIds.forEach((id, i) => {
        params[`VpcSecurityGroupIds.VpcSecurityGroupId.${i + 1}`] = id;
      });
    }
    if (options.Tags) {
      options.Tags.forEach((tag, i) => {
        params[`Tags.Tag.${i + 1}.Key`] = tag.Key;
        params[`Tags.Tag.${i + 1}.Value`] = tag.Value;
      });
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.CreateDBInstanceResult || result;
    return {
      DBInstance: response.DBInstance
    };
  }
  async createDBCluster(options) {
    const params = {
      Action: "CreateDBCluster",
      Version: "2014-10-31",
      DBClusterIdentifier: options.DBClusterIdentifier,
      Engine: options.Engine
    };
    if (options.EngineVersion)
      params.EngineVersion = options.EngineVersion;
    if (options.MasterUsername)
      params.MasterUsername = options.MasterUsername;
    if (options.MasterUserPassword)
      params.MasterUserPassword = options.MasterUserPassword;
    if (options.DatabaseName)
      params.DatabaseName = options.DatabaseName;
    if (options.DBSubnetGroupName)
      params.DBSubnetGroupName = options.DBSubnetGroupName;
    if (options.BackupRetentionPeriod !== undefined)
      params.BackupRetentionPeriod = options.BackupRetentionPeriod;
    if (options.StorageEncrypted !== undefined)
      params.StorageEncrypted = options.StorageEncrypted;
    if (options.KmsKeyId)
      params.KmsKeyId = options.KmsKeyId;
    if (options.DeletionProtection !== undefined)
      params.DeletionProtection = options.DeletionProtection;
    if (options.ServerlessV2ScalingConfiguration) {
      params["ServerlessV2ScalingConfiguration.MinCapacity"] = options.ServerlessV2ScalingConfiguration.MinCapacity;
      params["ServerlessV2ScalingConfiguration.MaxCapacity"] = options.ServerlessV2ScalingConfiguration.MaxCapacity;
    }
    options.VpcSecurityGroupIds?.forEach((id, index) => {
      params[`VpcSecurityGroupIds.VpcSecurityGroupId.${index + 1}`] = id;
    });
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: new URLSearchParams(buildQueryParams(params)).toString()
    });
    const response = result.CreateDBClusterResult || result;
    return { DBCluster: response.DBCluster };
  }
  async deleteDBInstance(options) {
    const params = {
      Action: "DeleteDBInstance",
      Version: "2014-10-31",
      DBInstanceIdentifier: options.DBInstanceIdentifier
    };
    if (options.SkipFinalSnapshot !== undefined) {
      params.SkipFinalSnapshot = options.SkipFinalSnapshot;
    }
    if (options.FinalDBSnapshotIdentifier) {
      params.FinalDBSnapshotIdentifier = options.FinalDBSnapshotIdentifier;
    }
    if (options.DeleteAutomatedBackups !== undefined) {
      params.DeleteAutomatedBackups = options.DeleteAutomatedBackups;
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.DeleteDBInstanceResult || result;
    return {
      DBInstance: response.DBInstance
    };
  }
  async modifyDBInstance(options) {
    const params = {
      Action: "ModifyDBInstance",
      Version: "2014-10-31",
      DBInstanceIdentifier: options.DBInstanceIdentifier
    };
    if (options.DBInstanceClass)
      params.DBInstanceClass = options.DBInstanceClass;
    if (options.AllocatedStorage)
      params.AllocatedStorage = options.AllocatedStorage;
    if (options.MasterUserPassword)
      params.MasterUserPassword = options.MasterUserPassword;
    if (options.BackupRetentionPeriod !== undefined)
      params.BackupRetentionPeriod = options.BackupRetentionPeriod;
    if (options.PreferredBackupWindow)
      params.PreferredBackupWindow = options.PreferredBackupWindow;
    if (options.PreferredMaintenanceWindow)
      params.PreferredMaintenanceWindow = options.PreferredMaintenanceWindow;
    if (options.MultiAZ !== undefined)
      params.MultiAZ = options.MultiAZ;
    if (options.EngineVersion)
      params.EngineVersion = options.EngineVersion;
    if (options.AutoMinorVersionUpgrade !== undefined)
      params.AutoMinorVersionUpgrade = options.AutoMinorVersionUpgrade;
    if (options.PubliclyAccessible !== undefined)
      params.PubliclyAccessible = options.PubliclyAccessible;
    if (options.ApplyImmediately !== undefined)
      params.ApplyImmediately = options.ApplyImmediately;
    if (options.StorageType)
      params.StorageType = options.StorageType;
    if (options.DeletionProtection !== undefined)
      params.DeletionProtection = options.DeletionProtection;
    if (options.VpcSecurityGroupIds) {
      options.VpcSecurityGroupIds.forEach((id, i) => {
        params[`VpcSecurityGroupIds.VpcSecurityGroupId.${i + 1}`] = id;
      });
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.ModifyDBInstanceResult || result;
    return {
      DBInstance: response.DBInstance
    };
  }
  async modifyDBCluster(options) {
    const params = {
      Action: "ModifyDBCluster",
      Version: "2014-10-31",
      DBClusterIdentifier: options.DBClusterIdentifier
    };
    if (options.ServerlessV2ScalingConfiguration) {
      params["ServerlessV2ScalingConfiguration.MinCapacity"] = options.ServerlessV2ScalingConfiguration.MinCapacity;
      params["ServerlessV2ScalingConfiguration.MaxCapacity"] = options.ServerlessV2ScalingConfiguration.MaxCapacity;
    }
    if (options.BackupRetentionPeriod !== undefined)
      params.BackupRetentionPeriod = options.BackupRetentionPeriod;
    if (options.EngineVersion)
      params.EngineVersion = options.EngineVersion;
    if (options.MasterUserPassword)
      params.MasterUserPassword = options.MasterUserPassword;
    if (options.DeletionProtection !== undefined)
      params.DeletionProtection = options.DeletionProtection;
    if (options.ApplyImmediately !== undefined)
      params.ApplyImmediately = options.ApplyImmediately;
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: queryString
    });
    const response = result.ModifyDBClusterResult || result;
    return { DBCluster: response.DBCluster };
  }
  async rebootDBCluster(dbClusterIdentifier) {
    const params = {
      Action: "FailoverDBCluster",
      Version: "2014-10-31",
      DBClusterIdentifier: dbClusterIdentifier
    };
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: new URLSearchParams(buildQueryParams(params)).toString()
    });
    const response = result.FailoverDBClusterResult || result;
    return { DBCluster: response.DBCluster };
  }
  async createDBClusterSnapshot(dbClusterIdentifier, snapshotIdentifier) {
    const params = {
      Action: "CreateDBClusterSnapshot",
      Version: "2014-10-31",
      DBClusterIdentifier: dbClusterIdentifier,
      DBClusterSnapshotIdentifier: snapshotIdentifier
    };
    return this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: new URLSearchParams(buildQueryParams(params)).toString()
    });
  }
  async describeDBClusterSnapshots(options = {}) {
    const params = {
      Action: "DescribeDBClusterSnapshots",
      Version: "2014-10-31",
      ...options
    };
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: new URLSearchParams(buildQueryParams(params)).toString()
    });
    const response = result.DescribeDBClusterSnapshotsResult || result;
    const snapshots = response.DBClusterSnapshots?.DBClusterSnapshot ?? response.DBClusterSnapshots ?? [];
    return { DBClusterSnapshots: Array.isArray(snapshots) ? snapshots : [snapshots] };
  }
  async deleteDBClusterSnapshot(snapshotIdentifier) {
    await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: new URLSearchParams(buildQueryParams({
        Action: "DeleteDBClusterSnapshot",
        Version: "2014-10-31",
        DBClusterSnapshotIdentifier: snapshotIdentifier
      })).toString()
    });
  }
  async deleteDBCluster(dbClusterIdentifier, finalSnapshotIdentifier) {
    const params = {
      Action: "DeleteDBCluster",
      Version: "2014-10-31",
      DBClusterIdentifier: dbClusterIdentifier,
      SkipFinalSnapshot: !finalSnapshotIdentifier
    };
    if (finalSnapshotIdentifier)
      params.FinalDBSnapshotIdentifier = finalSnapshotIdentifier;
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: new URLSearchParams(buildQueryParams(params)).toString()
    });
    const response = result.DeleteDBClusterResult || result;
    return { DBCluster: response.DBCluster };
  }
  async restoreDBClusterToPointInTime(options) {
    const params = {
      Action: "RestoreDBClusterToPointInTime",
      Version: "2014-10-31",
      DBClusterIdentifier: options.DBClusterIdentifier,
      SourceDBClusterIdentifier: options.SourceDBClusterIdentifier
    };
    if (options.RestoreToTime)
      params.RestoreToTime = options.RestoreToTime.toISOString();
    if (options.UseLatestRestorableTime)
      params.UseLatestRestorableTime = true;
    if (options.DBSubnetGroupName)
      params.DBSubnetGroupName = options.DBSubnetGroupName;
    if (options.VpcSecurityGroupIds) {
      options.VpcSecurityGroupIds.forEach((id, i) => {
        params[`VpcSecurityGroupIds.VpcSecurityGroupId.${i + 1}`] = id;
      });
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: queryString
    });
    const response = result.RestoreDBClusterToPointInTimeResult || result;
    return { DBCluster: response.DBCluster };
  }
  async restoreDBClusterFromSnapshot(options) {
    const params = {
      Action: "RestoreDBClusterFromSnapshot",
      Version: "2014-10-31",
      DBClusterIdentifier: options.DBClusterIdentifier,
      SnapshotIdentifier: options.SnapshotIdentifier,
      Engine: options.Engine
    };
    if (options.EngineVersion)
      params.EngineVersion = options.EngineVersion;
    if (options.DBSubnetGroupName)
      params.DBSubnetGroupName = options.DBSubnetGroupName;
    if (options.DeletionProtection !== undefined)
      params.DeletionProtection = options.DeletionProtection;
    options.VpcSecurityGroupIds?.forEach((id, index) => {
      params[`VpcSecurityGroupIds.VpcSecurityGroupId.${index + 1}`] = id;
    });
    if (options.ServerlessV2ScalingConfiguration) {
      params["ServerlessV2ScalingConfiguration.MinCapacity"] = options.ServerlessV2ScalingConfiguration.MinCapacity;
      params["ServerlessV2ScalingConfiguration.MaxCapacity"] = options.ServerlessV2ScalingConfiguration.MaxCapacity;
    }
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: new URLSearchParams(buildQueryParams(params)).toString()
    });
    const response = result.RestoreDBClusterFromSnapshotResult || result;
    return { DBCluster: response.DBCluster };
  }
  async startDBInstance(dbInstanceIdentifier) {
    const params = {
      Action: "StartDBInstance",
      Version: "2014-10-31",
      DBInstanceIdentifier: dbInstanceIdentifier
    };
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.StartDBInstanceResult || result;
    return {
      DBInstance: response.DBInstance
    };
  }
  async stopDBInstance(options) {
    const params = {
      Action: "StopDBInstance",
      Version: "2014-10-31",
      DBInstanceIdentifier: options.DBInstanceIdentifier
    };
    if (options.DBSnapshotIdentifier) {
      params.DBSnapshotIdentifier = options.DBSnapshotIdentifier;
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.StopDBInstanceResult || result;
    return {
      DBInstance: response.DBInstance
    };
  }
  async rebootDBInstance(options) {
    const params = {
      Action: "RebootDBInstance",
      Version: "2014-10-31",
      DBInstanceIdentifier: options.DBInstanceIdentifier
    };
    if (options.ForceFailover !== undefined) {
      params.ForceFailover = options.ForceFailover;
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.RebootDBInstanceResult || result;
    return {
      DBInstance: response.DBInstance
    };
  }
  async createDBSnapshot(options) {
    const params = {
      Action: "CreateDBSnapshot",
      Version: "2014-10-31",
      DBInstanceIdentifier: options.DBInstanceIdentifier,
      DBSnapshotIdentifier: options.DBSnapshotIdentifier
    };
    if (options.Tags) {
      options.Tags.forEach((tag, i) => {
        params[`Tags.Tag.${i + 1}.Key`] = tag.Key;
        params[`Tags.Tag.${i + 1}.Value`] = tag.Value;
      });
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.CreateDBSnapshotResult || result;
    return {
      DBSnapshot: response.DBSnapshot
    };
  }
  async deleteDBSnapshot(dbSnapshotIdentifier) {
    const params = {
      Action: "DeleteDBSnapshot",
      Version: "2014-10-31",
      DBSnapshotIdentifier: dbSnapshotIdentifier
    };
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.DeleteDBSnapshotResult || result;
    return {
      DBSnapshot: response.DBSnapshot
    };
  }
  async restoreDBInstanceFromDBSnapshot(options) {
    const params = {
      Action: "RestoreDBInstanceFromDBSnapshot",
      Version: "2014-10-31",
      DBInstanceIdentifier: options.DBInstanceIdentifier,
      DBSnapshotIdentifier: options.DBSnapshotIdentifier
    };
    if (options.DBInstanceClass)
      params.DBInstanceClass = options.DBInstanceClass;
    if (options.Port)
      params.Port = options.Port;
    if (options.AvailabilityZone)
      params.AvailabilityZone = options.AvailabilityZone;
    if (options.DBSubnetGroupName)
      params.DBSubnetGroupName = options.DBSubnetGroupName;
    if (options.MultiAZ !== undefined)
      params.MultiAZ = options.MultiAZ;
    if (options.PubliclyAccessible !== undefined)
      params.PubliclyAccessible = options.PubliclyAccessible;
    if (options.AutoMinorVersionUpgrade !== undefined)
      params.AutoMinorVersionUpgrade = options.AutoMinorVersionUpgrade;
    if (options.StorageType)
      params.StorageType = options.StorageType;
    if (options.DeletionProtection !== undefined)
      params.DeletionProtection = options.DeletionProtection;
    if (options.VpcSecurityGroupIds) {
      options.VpcSecurityGroupIds.forEach((id, i) => {
        params[`VpcSecurityGroupIds.VpcSecurityGroupId.${i + 1}`] = id;
      });
    }
    if (options.Tags) {
      options.Tags.forEach((tag, i) => {
        params[`Tags.Tag.${i + 1}.Key`] = tag.Key;
        params[`Tags.Tag.${i + 1}.Value`] = tag.Value;
      });
    }
    const queryString = new URLSearchParams(buildQueryParams(params)).toString();
    const result = await this.client.request({
      service: "rds",
      region: this.region,
      method: "POST",
      path: "/",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      body: queryString
    });
    const response = result.RestoreDBInstanceFromDBSnapshotResult || result;
    return {
      DBInstance: response.DBInstance
    };
  }
  async waitForDBInstanceAvailable(dbInstanceIdentifier, maxAttempts = 60, delayMs = 30000) {
    for (let i = 0;i < maxAttempts; i++) {
      const instance = await this.describeDBInstance(dbInstanceIdentifier);
      if (instance?.DBInstanceStatus === "available") {
        return instance;
      }
      if (["deleted", "failed", "incompatible-restore", "incompatible-parameters"].includes(instance?.DBInstanceStatus || "")) {
        throw new Error(`DB instance ${dbInstanceIdentifier} is in terminal state: ${instance?.DBInstanceStatus}`);
      }
      await new Promise((resolve) => setTimeout(resolve, delayMs));
    }
    throw new Error(`Timeout waiting for DB instance ${dbInstanceIdentifier} to become available`);
  }
  async waitForDBInstanceDeleted(dbInstanceIdentifier, maxAttempts = 60, delayMs = 30000) {
    for (let i = 0;i < maxAttempts; i++) {
      try {
        const instance = await this.describeDBInstance(dbInstanceIdentifier);
        if (instance?.DBInstanceStatus === "deleting") {
          await new Promise((resolve) => setTimeout(resolve, delayMs));
          continue;
        }
        throw new Error(`DB instance ${dbInstanceIdentifier} is in state: ${instance?.DBInstanceStatus}`);
      } catch (error) {
        if (error.code === "DBInstanceNotFound" || error.code === "DBInstanceNotFoundFault") {
          return;
        }
        throw error;
      }
    }
    throw new Error(`Timeout waiting for DB instance ${dbInstanceIdentifier} to be deleted`);
  }
}

export { RDSClient };
