import * as HttpClient from "effect/unstable/http/HttpClient";
import * as S from "effect/Schema";
import * as API from "../client/api.js";
import * as T from "../traits.js";
import * as C from "../category.js";
const svc = T.AwsApiService({
    sdkId: "RDS Data",
    serviceShapeName: "RdsDataService",
});
const auth = T.AwsAuthSigv4({ name: "rds-data" });
const ver = T.ServiceVersion("2018-08-01");
const proto = T.AwsProtocolsRestJson1();
const rules = T.EndpointResolver((p, _) => {
    const { Region, UseDualStack = false, UseFIPS = false, Endpoint } = p;
    const e = (u, p = {}, h = {}) => ({
        type: "endpoint",
        endpoint: { url: u, properties: p, headers: h },
    });
    const err = (m) => ({
        type: "error",
        message: m,
    });
    if (Endpoint != null) {
        if (UseFIPS === true) {
            return err("Invalid Configuration: FIPS and custom endpoint are not supported");
        }
        if (UseDualStack === true) {
            return err("Invalid Configuration: Dualstack and custom endpoint are not supported");
        }
        return e(Endpoint);
    }
    if (Region != null) {
        {
            const PartitionResult = _.partition(Region);
            if (PartitionResult != null && PartitionResult !== false) {
                if (UseFIPS === true && UseDualStack === true) {
                    if (true === _.getAttr(PartitionResult, "supportsFIPS") &&
                        true === _.getAttr(PartitionResult, "supportsDualStack")) {
                        return e(`https://rds-data-fips.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}`);
                    }
                    return err("FIPS and DualStack are enabled, but this partition does not support one or both");
                }
                if (UseFIPS === true) {
                    if (_.getAttr(PartitionResult, "supportsFIPS") === true) {
                        return e(`https://rds-data-fips.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}`);
                    }
                    return err("FIPS is enabled but this partition does not support FIPS");
                }
                if (UseDualStack === true) {
                    if (true === _.getAttr(PartitionResult, "supportsDualStack")) {
                        return e(`https://rds-data.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}`);
                    }
                    return err("DualStack is enabled but this partition does not support DualStack");
                }
                return e(`https://rds-data.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}`);
            }
        }
    }
    return err("Invalid Configuration: Missing Region");
});
export const BooleanArray = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.Boolean);
export const LongArray = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.Number);
export const DoubleArray = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.Number);
export const StringArray = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.String);
export const ArrayOfArray = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.suspend(() => ArrayValue).annotate({ identifier: "ArrayValue" }));
export const ArrayValue = /*@__PURE__*/ /*#__PURE__*/ S.Union([
    S.Struct({ booleanValues: BooleanArray }),
    S.Struct({ longValues: LongArray }),
    S.Struct({ doubleValues: DoubleArray }),
    S.Struct({ stringValues: StringArray }),
    S.Struct({
        arrayValues: S.suspend(() => ArrayOfArray).annotate({
            identifier: "ArrayOfArray",
        }),
    }),
]);
export const Field = /*@__PURE__*/ /*#__PURE__*/ S.Union([
    S.Struct({ isNull: S.Boolean }),
    S.Struct({ booleanValue: S.Boolean }),
    S.Struct({ longValue: S.Number }),
    S.Struct({ doubleValue: S.Number }),
    S.Struct({ stringValue: S.String }),
    S.Struct({ blobValue: T.Blob }),
    S.Struct({ arrayValue: ArrayValue }),
]);
export const SqlParameter = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    name: S.optional(S.String),
    value: S.optional(Field),
    typeHint: S.optional(S.String),
})).annotate({ identifier: "SqlParameter" });
export const SqlParametersList = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(SqlParameter);
export const SqlParameterSets = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(SqlParametersList);
export const BatchExecuteStatementRequest = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    resourceArn: S.String,
    secretArn: S.String,
    sql: S.String,
    database: S.optional(S.String),
    schema: S.optional(S.String),
    parameterSets: S.optional(SqlParameterSets),
    transactionId: S.optional(S.String),
}).pipe(T.all(T.Http({ method: "POST", uri: "/BatchExecute" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "BatchExecuteStatementRequest",
});
export const FieldList = /*@__PURE__*/ /*#__PURE__*/ S.Array(Field);
export const UpdateResult = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ generatedFields: S.optional(FieldList) })).annotate({ identifier: "UpdateResult" });
export const UpdateResults = /*@__PURE__*/ /*#__PURE__*/ S.Array(UpdateResult);
export const BatchExecuteStatementResponse = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ updateResults: S.optional(UpdateResults) })).annotate({
    identifier: "BatchExecuteStatementResponse",
});
export const BeginTransactionRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    resourceArn: S.String,
    secretArn: S.String,
    database: S.optional(S.String),
    schema: S.optional(S.String),
}).pipe(T.all(T.Http({ method: "POST", uri: "/BeginTransaction" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "BeginTransactionRequest",
});
export const BeginTransactionResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ transactionId: S.optional(S.String) })).annotate({
    identifier: "BeginTransactionResponse",
});
export const CommitTransactionRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    resourceArn: S.String,
    secretArn: S.String,
    transactionId: S.String,
}).pipe(T.all(T.Http({ method: "POST", uri: "/CommitTransaction" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "CommitTransactionRequest",
});
export const CommitTransactionResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ transactionStatus: S.optional(S.String) })).annotate({
    identifier: "CommitTransactionResponse",
});
export const ExecuteSqlRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    dbClusterOrInstanceArn: S.String,
    awsSecretStoreArn: S.String,
    sqlStatements: S.String,
    database: S.optional(S.String),
    schema: S.optional(S.String),
}).pipe(T.all(T.Http({ method: "POST", uri: "/ExecuteSql" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ExecuteSqlRequest",
});
export const ColumnMetadata = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    name: S.optional(S.String),
    type: S.optional(S.Number),
    typeName: S.optional(S.String),
    label: S.optional(S.String),
    schemaName: S.optional(S.String),
    tableName: S.optional(S.String),
    isAutoIncrement: S.optional(S.Boolean),
    isSigned: S.optional(S.Boolean),
    isCurrency: S.optional(S.Boolean),
    isCaseSensitive: S.optional(S.Boolean),
    nullable: S.optional(S.Number),
    precision: S.optional(S.Number),
    scale: S.optional(S.Number),
    arrayBaseColumnType: S.optional(S.Number),
})).annotate({ identifier: "ColumnMetadata" });
export const Metadata = /*@__PURE__*/ /*#__PURE__*/ S.Array(ColumnMetadata);
export const ResultSetMetadata = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    columnCount: S.optional(S.Number),
    columnMetadata: S.optional(Metadata),
})).annotate({
    identifier: "ResultSetMetadata",
});
export const ArrayValueList = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.suspend(() => Value).annotate({ identifier: "Value" }));
export const StructValue = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    attributes: S.optional(S.suspend(() => ArrayValueList).annotate({
        identifier: "ArrayValueList",
    })),
})).annotate({ identifier: "StructValue" });
export const Value = /*@__PURE__*/ /*#__PURE__*/ S.Union([
    S.Struct({ isNull: S.Boolean }),
    S.Struct({ bitValue: S.Boolean }),
    S.Struct({ bigIntValue: S.Number }),
    S.Struct({ intValue: S.Number }),
    S.Struct({ doubleValue: S.Number }),
    S.Struct({ realValue: S.Number }),
    S.Struct({ stringValue: S.String }),
    S.Struct({ blobValue: T.Blob }),
    S.Struct({
        arrayValues: S.suspend(() => ArrayValueList).annotate({
            identifier: "ArrayValueList",
        }),
    }),
    S.Struct({
        structValue: S.suspend(() => StructValue).annotate({
            identifier: "StructValue",
        }),
    }),
]);
export const Row = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.suspend(() => Value).annotate({ identifier: "Value" }));
export const Record = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ values: S.optional(Row) })).annotate({ identifier: "Record" });
export const Records = /*@__PURE__*/ /*#__PURE__*/ S.Array(Record);
export const ResultFrame = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    resultSetMetadata: S.optional(ResultSetMetadata),
    records: S.optional(Records),
})).annotate({ identifier: "ResultFrame" });
export const SqlStatementResult = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    resultFrame: S.optional(ResultFrame),
    numberOfRecordsUpdated: S.optional(S.Number),
})).annotate({
    identifier: "SqlStatementResult",
});
export const SqlStatementResults = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(SqlStatementResult);
export const ExecuteSqlResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ sqlStatementResults: S.optional(SqlStatementResults) })).annotate({
    identifier: "ExecuteSqlResponse",
});
export const ResultSetOptions = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    decimalReturnType: S.optional(S.String),
    longReturnType: S.optional(S.String),
})).annotate({
    identifier: "ResultSetOptions",
});
export const ExecuteStatementRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    resourceArn: S.String,
    secretArn: S.String,
    sql: S.String,
    database: S.optional(S.String),
    schema: S.optional(S.String),
    parameters: S.optional(SqlParametersList),
    transactionId: S.optional(S.String),
    includeResultMetadata: S.optional(S.Boolean),
    continueAfterTimeout: S.optional(S.Boolean),
    resultSetOptions: S.optional(ResultSetOptions),
    formatRecordsAs: S.optional(S.String),
}).pipe(T.all(T.Http({ method: "POST", uri: "/Execute" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ExecuteStatementRequest",
});
export const SqlRecords = /*@__PURE__*/ /*#__PURE__*/ S.Array(FieldList);
export const ExecuteStatementResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    records: S.optional(SqlRecords),
    columnMetadata: S.optional(Metadata),
    numberOfRecordsUpdated: S.optional(S.Number),
    generatedFields: S.optional(FieldList),
    formattedRecords: S.optional(S.String),
})).annotate({
    identifier: "ExecuteStatementResponse",
});
export const RollbackTransactionRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    resourceArn: S.String,
    secretArn: S.String,
    transactionId: S.String,
}).pipe(T.all(T.Http({ method: "POST", uri: "/RollbackTransaction" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "RollbackTransactionRequest",
});
export const RollbackTransactionResponse = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ transactionStatus: S.optional(S.String) })).annotate({
    identifier: "RollbackTransactionResponse",
});
//# Errors
export class AccessDeniedException extends S.TaggedErrorClass()("AccessDeniedException", { message: S.optional(S.String) }).pipe(C.withAuthError) {
}
export class BadRequestException extends S.TaggedErrorClass()("BadRequestException", { message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class DatabaseErrorException extends S.TaggedErrorClass()("DatabaseErrorException", { message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class DatabaseNotFoundException extends S.TaggedErrorClass()("DatabaseNotFoundException", { message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class DatabaseResumingException extends S.TaggedErrorClass()("DatabaseResumingException", { message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class DatabaseUnavailableException extends S.TaggedErrorClass()("DatabaseUnavailableException", {}).pipe(C.withTimeoutError) {
}
export class ForbiddenException extends S.TaggedErrorClass()("ForbiddenException", { message: S.optional(S.String) }).pipe(C.withAuthError) {
}
export class HttpEndpointNotEnabledException extends S.TaggedErrorClass()("HttpEndpointNotEnabledException", { message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class InternalServerErrorException extends S.TaggedErrorClass()("InternalServerErrorException", {}).pipe(C.withServerError) {
}
export class InvalidResourceStateException extends S.TaggedErrorClass()("InvalidResourceStateException", { message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class InvalidSecretException extends S.TaggedErrorClass()("InvalidSecretException", { message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class SecretsErrorException extends S.TaggedErrorClass()("SecretsErrorException", { message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class ServiceUnavailableError extends S.TaggedErrorClass()("ServiceUnavailableError", {}).pipe(C.withServerError) {
}
export class StatementTimeoutException extends S.TaggedErrorClass()("StatementTimeoutException", { message: S.optional(S.String), dbConnectionId: S.optional(S.Number) }).pipe(C.withBadRequestError) {
}
export class TransactionNotFoundException extends S.TaggedErrorClass()("TransactionNotFoundException", { message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class NotFoundException extends S.TaggedErrorClass()("NotFoundException", { message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class UnsupportedResultException extends S.TaggedErrorClass()("UnsupportedResultException", { message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
/**
 * Runs a batch SQL statement over an array of data.
 *
 * You can run bulk update and insert operations for multiple records using a DML
 * statement with different parameter sets. Bulk operations can provide a significant
 * performance improvement over individual insert and update operations.
 *
 * If a call isn't part of a transaction because it doesn't include the `transactionID` parameter,
 * changes that result from the call are committed automatically.
 *
 * There isn't a fixed upper limit on the number of parameter sets. However, the maximum size of the HTTP request
 * submitted through the Data API is 4 MiB. If the request exceeds this limit, the Data API returns an error and doesn't
 * process the request. This 4-MiB limit includes the size of the HTTP headers and the JSON notation in the request. Thus, the
 * number of parameter sets that you can include depends on a combination of factors, such as the size of the SQL statement and
 * the size of each parameter set.
 *
 * The response size limit is 1 MiB. If the call returns more than 1 MiB of response data, the call is terminated.
 */
export const batchExecuteStatement = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: BatchExecuteStatementRequest,
    output: BatchExecuteStatementResponse,
    errors: [
        AccessDeniedException,
        BadRequestException,
        DatabaseErrorException,
        DatabaseNotFoundException,
        DatabaseResumingException,
        DatabaseUnavailableException,
        ForbiddenException,
        HttpEndpointNotEnabledException,
        InternalServerErrorException,
        InvalidResourceStateException,
        InvalidSecretException,
        SecretsErrorException,
        ServiceUnavailableError,
        StatementTimeoutException,
        TransactionNotFoundException,
    ],
}));
/**
 * Starts a SQL transaction.
 *
 * A transaction can run for a maximum of 24 hours. A transaction is terminated and rolled back automatically after 24
 * hours.
 *
 * A transaction times out if no calls use its transaction ID in three minutes. If a transaction times out before it's
 * committed, it's rolled back automatically.
 *
 * For Aurora MySQL, DDL statements inside a transaction cause an implicit commit. We recommend that you run each MySQL DDL statement in a separate
 * `ExecuteStatement` call with `continueAfterTimeout` enabled.
 */
export const beginTransaction = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: BeginTransactionRequest,
    output: BeginTransactionResponse,
    errors: [
        AccessDeniedException,
        BadRequestException,
        DatabaseErrorException,
        DatabaseNotFoundException,
        DatabaseResumingException,
        DatabaseUnavailableException,
        ForbiddenException,
        HttpEndpointNotEnabledException,
        InternalServerErrorException,
        InvalidResourceStateException,
        InvalidSecretException,
        SecretsErrorException,
        ServiceUnavailableError,
        StatementTimeoutException,
        TransactionNotFoundException,
    ],
}));
/**
 * Ends a SQL transaction started with the `BeginTransaction` operation and
 * commits the changes.
 */
export const commitTransaction = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: CommitTransactionRequest,
    output: CommitTransactionResponse,
    errors: [
        AccessDeniedException,
        BadRequestException,
        DatabaseErrorException,
        DatabaseNotFoundException,
        DatabaseUnavailableException,
        ForbiddenException,
        HttpEndpointNotEnabledException,
        InternalServerErrorException,
        InvalidResourceStateException,
        InvalidSecretException,
        NotFoundException,
        SecretsErrorException,
        ServiceUnavailableError,
        StatementTimeoutException,
        TransactionNotFoundException,
    ],
}));
/**
 * Runs one or more SQL statements.
 *
 * This operation isn't supported for Aurora Serverless v2 and provisioned DB clusters.
 * For Aurora Serverless v1 DB clusters, the operation is deprecated.
 * Use the `BatchExecuteStatement` or `ExecuteStatement` operation.
 */
export const executeSql = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: ExecuteSqlRequest,
    output: ExecuteSqlResponse,
    errors: [
        AccessDeniedException,
        BadRequestException,
        ForbiddenException,
        InternalServerErrorException,
        ServiceUnavailableError,
    ],
}));
/**
 * Runs a SQL statement against a database.
 *
 * If a call isn't part of a transaction because it doesn't include the
 * `transactionID` parameter, changes that result from the call are
 * committed automatically.
 *
 * If the binary response data from the database is more than 1 MB, the call is terminated.
 */
export const executeStatement = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: ExecuteStatementRequest,
    output: ExecuteStatementResponse,
    errors: [
        AccessDeniedException,
        BadRequestException,
        DatabaseErrorException,
        DatabaseNotFoundException,
        DatabaseResumingException,
        DatabaseUnavailableException,
        ForbiddenException,
        HttpEndpointNotEnabledException,
        InternalServerErrorException,
        InvalidResourceStateException,
        InvalidSecretException,
        SecretsErrorException,
        ServiceUnavailableError,
        StatementTimeoutException,
        TransactionNotFoundException,
        UnsupportedResultException,
    ],
}));
/**
 * Performs a rollback of a transaction. Rolling back a transaction cancels its changes.
 */
export const rollbackTransaction = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: RollbackTransactionRequest,
    output: RollbackTransactionResponse,
    errors: [
        AccessDeniedException,
        BadRequestException,
        DatabaseErrorException,
        DatabaseNotFoundException,
        DatabaseUnavailableException,
        ForbiddenException,
        HttpEndpointNotEnabledException,
        InternalServerErrorException,
        InvalidResourceStateException,
        InvalidSecretException,
        NotFoundException,
        SecretsErrorException,
        ServiceUnavailableError,
        StatementTimeoutException,
        TransactionNotFoundException,
    ],
}));
//# sourceMappingURL=rds-data.js.map