import * as HttpClient from "effect/unstable/http/HttpClient";
import * as S from "effect/Schema";
import * as stream from "effect/Stream";
import * as API from "../client/api.js";
import * as T from "../traits.js";
import * as C from "../category.js";
const svc = T.AwsApiService({
    sdkId: "BCM Data Exports",
    serviceShapeName: "AWSBillingAndCostManagementDataExports",
});
const auth = T.AwsAuthSigv4({ name: "bcm-data-exports" });
const ver = T.ServiceVersion("2023-11-26");
const proto = T.AwsProtocolsAwsJson1_1();
const rules = T.EndpointResolver((p, _) => {
    const { UseFIPS = false, Endpoint, Region } = p;
    const e = (u, p = {}, h = {}) => ({
        type: "endpoint",
        endpoint: { url: u, properties: p, headers: h },
    });
    const err = (m) => ({
        type: "error",
        message: m,
    });
    const _p0 = (_0) => ({
        authSchemes: [
            {
                name: "sigv4",
                signingRegion: `${_.getAttr(_0, "implicitGlobalRegion")}`,
            },
        ],
    });
    if (Endpoint != null) {
        if (UseFIPS === true) {
            return err("Invalid Configuration: FIPS and custom endpoint are not supported");
        }
        return e(Endpoint);
    }
    if (Region != null) {
        {
            const PartitionResult = _.partition(Region);
            if (PartitionResult != null && PartitionResult !== false) {
                if (_.getAttr(PartitionResult, "name") === "aws-iso" &&
                    UseFIPS === false) {
                    return e("https://bcm-data-exports.us-iso-east-1.c2s.ic.gov", {
                        authSchemes: [{ name: "sigv4", signingRegion: "us-iso-east-1" }],
                    }, {});
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso-b" &&
                    UseFIPS === false) {
                    return e("https://bcm-data-exports.us-isob-east-1.sc2s.sgov.gov", {
                        authSchemes: [{ name: "sigv4", signingRegion: "us-isob-east-1" }],
                    }, {});
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso-e" &&
                    UseFIPS === false) {
                    return e("https://bcm-data-exports.eu-isoe-west-1.cloud.adc-e.uk", {
                        authSchemes: [{ name: "sigv4", signingRegion: "eu-isoe-west-1" }],
                    }, {});
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso-f" &&
                    UseFIPS === false) {
                    return e("https://bcm-data-exports.us-isof-south-1.csp.hci.ic.gov", {
                        authSchemes: [
                            { name: "sigv4", signingRegion: "us-isof-south-1" },
                        ],
                    }, {});
                }
                if (UseFIPS === true) {
                    return e(`https://bcm-data-exports-fips.${_.getAttr(PartitionResult, "implicitGlobalRegion")}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}`, _p0(PartitionResult), {});
                }
                return e(`https://bcm-data-exports.${_.getAttr(PartitionResult, "implicitGlobalRegion")}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}`, _p0(PartitionResult), {});
            }
        }
    }
    return err("Invalid Configuration: Missing Region");
});
export const GetExecutionRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ExportArn: S.String, ExecutionId: S.String }).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "GetExecutionRequest",
});
export const TableProperties = /*@__PURE__*/ /*#__PURE__*/ S.Record(S.String, S.String.pipe(S.optional));
export const TableConfigurations = /*@__PURE__*/ /*#__PURE__*/ S.Record(S.String, TableProperties.pipe(S.optional));
export const DataQuery = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    QueryStatement: S.String,
    TableConfigurations: S.optional(TableConfigurations),
})).annotate({ identifier: "DataQuery" });
export const S3OutputType = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const FormatOption = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const CompressionOption = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const OverwriteOption = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const S3OutputConfigurations = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    OutputType: S3OutputType,
    Format: FormatOption,
    Compression: CompressionOption,
    Overwrite: OverwriteOption,
})).annotate({
    identifier: "S3OutputConfigurations",
});
export const S3Destination = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    S3Bucket: S.String,
    S3BucketOwner: S.optional(S.String),
    S3Prefix: S.String,
    S3Region: S.String,
    S3OutputConfigurations: S3OutputConfigurations,
})).annotate({ identifier: "S3Destination" });
export const DestinationConfigurations = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ S3Destination: S3Destination })).annotate({
    identifier: "DestinationConfigurations",
});
export const FrequencyOption = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const RefreshCadence = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Frequency: FrequencyOption })).annotate({ identifier: "RefreshCadence" });
export const Export = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ExportArn: S.optional(S.String),
    Name: S.String,
    Description: S.optional(S.String),
    DataQuery: DataQuery,
    DestinationConfigurations: DestinationConfigurations,
    RefreshCadence: RefreshCadence,
})).annotate({ identifier: "Export" });
export const ExecutionStatusCode = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const ExecutionStatusReason = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const ExecutionStatus = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    StatusCode: S.optional(ExecutionStatusCode),
    StatusReason: S.optional(ExecutionStatusReason),
    CreatedAt: S.optional(T.DateFromString.pipe(T.TimestampFormat("date-time"))),
    CompletedAt: S.optional(T.DateFromString.pipe(T.TimestampFormat("date-time"))),
    LastUpdatedAt: S.optional(T.DateFromString.pipe(T.TimestampFormat("date-time"))),
})).annotate({
    identifier: "ExecutionStatus",
});
export const GetExecutionResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ExecutionId: S.optional(S.String),
    Export: S.optional(Export),
    ExecutionStatus: S.optional(ExecutionStatus),
})).annotate({
    identifier: "GetExecutionResponse",
});
export const ValidationExceptionReason = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const ValidationExceptionField = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Name: S.String, Message: S.String })).annotate({
    identifier: "ValidationExceptionField",
});
export const ValidationExceptionFieldList = /*@__PURE__*/ /*#__PURE__*/ S.Array(ValidationExceptionField);
export const GetTableRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    TableName: S.String,
    TableProperties: S.optional(TableProperties),
}).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "GetTableRequest",
});
export const Column = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Name: S.optional(S.String),
    Type: S.optional(S.String),
    Description: S.optional(S.String),
})).annotate({ identifier: "Column" });
export const ColumnList = /*@__PURE__*/ /*#__PURE__*/ S.Array(Column);
export const GetTableResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    TableName: S.optional(S.String),
    Description: S.optional(S.String),
    TableProperties: S.optional(TableProperties),
    Schema: S.optional(ColumnList),
})).annotate({
    identifier: "GetTableResponse",
});
export const ListExecutionsRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ExportArn: S.String,
    MaxResults: S.optional(S.Number),
    NextToken: S.optional(S.String),
}).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ListExecutionsRequest",
});
export const ExecutionReference = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ExecutionId: S.String, ExecutionStatus: ExecutionStatus })).annotate({
    identifier: "ExecutionReference",
});
export const ExecutionReferenceList = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(ExecutionReference);
export const ListExecutionsResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Executions: S.optional(ExecutionReferenceList),
    NextToken: S.optional(S.String),
})).annotate({
    identifier: "ListExecutionsResponse",
});
export const ListTablesRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    NextToken: S.optional(S.String),
    MaxResults: S.optional(S.Number),
}).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ListTablesRequest",
});
export const GenericStringList = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.String);
export const TablePropertyDescription = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Name: S.optional(S.String),
    ValidValues: S.optional(GenericStringList),
    DefaultValue: S.optional(S.String),
    Description: S.optional(S.String),
})).annotate({
    identifier: "TablePropertyDescription",
});
export const TablePropertyDescriptionList = /*@__PURE__*/ /*#__PURE__*/ S.Array(TablePropertyDescription);
export const Table = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    TableName: S.optional(S.String),
    Description: S.optional(S.String),
    TableProperties: S.optional(TablePropertyDescriptionList),
})).annotate({ identifier: "Table" });
export const TableList = /*@__PURE__*/ /*#__PURE__*/ S.Array(Table);
export const ListTablesResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Tables: S.optional(TableList), NextToken: S.optional(S.String) })).annotate({
    identifier: "ListTablesResponse",
});
export const ListTagsForResourceRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ResourceArn: S.String,
    MaxResults: S.optional(S.Number),
    NextToken: S.optional(S.String),
}).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ListTagsForResourceRequest",
});
export const ResourceTag = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Key: S.String, Value: S.String })).annotate({ identifier: "ResourceTag" });
export const ResourceTagList = /*@__PURE__*/ /*#__PURE__*/ S.Array(ResourceTag);
export const ListTagsForResourceResponse = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ResourceTags: S.optional(ResourceTagList),
    NextToken: S.optional(S.String),
})).annotate({
    identifier: "ListTagsForResourceResponse",
});
export const TagResourceRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ResourceArn: S.String, ResourceTags: ResourceTagList }).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "TagResourceRequest",
});
export const TagResourceResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({})).annotate({
    identifier: "TagResourceResponse",
});
export const ResourceTagKeyList = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.String);
export const UntagResourceRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ResourceArn: S.String, ResourceTagKeys: ResourceTagKeyList }).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "UntagResourceRequest",
});
export const UntagResourceResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({})).annotate({
    identifier: "UntagResourceResponse",
});
export const CreateExportRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Export: Export, ResourceTags: S.optional(ResourceTagList) }).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "CreateExportRequest",
});
export const CreateExportResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ExportArn: S.optional(S.String) })).annotate({
    identifier: "CreateExportResponse",
});
export const GetExportRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ExportArn: S.String }).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "GetExportRequest",
});
export const ExportStatusCode = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const ExportStatus = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    StatusCode: S.optional(ExportStatusCode),
    StatusReason: S.optional(ExecutionStatusReason),
    CreatedAt: S.optional(T.DateFromString.pipe(T.TimestampFormat("date-time"))),
    LastUpdatedAt: S.optional(T.DateFromString.pipe(T.TimestampFormat("date-time"))),
    LastRefreshedAt: S.optional(T.DateFromString.pipe(T.TimestampFormat("date-time"))),
})).annotate({ identifier: "ExportStatus" });
export const GetExportResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Export: S.optional(Export),
    ExportStatus: S.optional(ExportStatus),
})).annotate({
    identifier: "GetExportResponse",
});
export const UpdateExportRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ExportArn: S.String, Export: Export }).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "UpdateExportRequest",
});
export const UpdateExportResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ExportArn: S.optional(S.String) })).annotate({
    identifier: "UpdateExportResponse",
});
export const DeleteExportRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ExportArn: S.String }).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "DeleteExportRequest",
});
export const DeleteExportResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ExportArn: S.optional(S.String) })).annotate({
    identifier: "DeleteExportResponse",
});
export const ListExportsRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    MaxResults: S.optional(S.Number),
    NextToken: S.optional(S.String),
}).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ListExportsRequest",
});
export const ExportReference = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ExportArn: S.String,
    ExportName: S.String,
    ExportStatus: ExportStatus,
})).annotate({
    identifier: "ExportReference",
});
export const ExportReferenceList = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(ExportReference);
export const ListExportsResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Exports: S.optional(ExportReferenceList),
    NextToken: S.optional(S.String),
})).annotate({
    identifier: "ListExportsResponse",
});
//# Errors
export class InternalServerException extends S.TaggedErrorClass()("InternalServerException", { Message: S.String }).pipe(C.withServerError) {
}
export class ResourceNotFoundException extends S.TaggedErrorClass()("ResourceNotFoundException", { Message: S.String, ResourceId: S.String, ResourceType: S.String }).pipe(C.withBadRequestError) {
}
export class ThrottlingException extends S.TaggedErrorClass()("ThrottlingException", {
    Message: S.String,
    QuotaCode: S.optional(S.String),
    ServiceCode: S.optional(S.String),
}).pipe(C.withThrottlingError) {
}
export class ValidationException extends S.TaggedErrorClass()("ValidationException", {
    Message: S.String,
    Reason: S.optional(ValidationExceptionReason),
    Fields: S.optional(ValidationExceptionFieldList),
}).pipe(C.withBadRequestError) {
}
export class AccessDeniedException extends S.TaggedErrorClass()("AccessDeniedException", { Message: S.String }).pipe(C.withAuthError) {
}
export class ServiceQuotaExceededException extends S.TaggedErrorClass()("ServiceQuotaExceededException", {
    Message: S.String,
    ResourceId: S.optional(S.String),
    ResourceType: S.optional(S.String),
    QuotaCode: S.String,
    ServiceCode: S.String,
}).pipe(C.withQuotaError) {
}
/**
 * Exports data based on the source data update.
 */
export const getExecution = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetExecutionRequest,
    output: GetExecutionResponse,
    errors: [
        InternalServerException,
        ResourceNotFoundException,
        ThrottlingException,
        ValidationException,
    ],
}));
/**
 * Returns the metadata for the specified table and table properties. This includes the list of columns in the table schema, their data types, and column descriptions.
 */
export const getTable = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetTableRequest,
    output: GetTableResponse,
    errors: [InternalServerException, ThrottlingException, ValidationException],
}));
/**
 * Lists the historical executions for the export.
 */
export const listExecutions = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListExecutionsRequest,
    output: ListExecutionsResponse,
    errors: [
        InternalServerException,
        ResourceNotFoundException,
        ThrottlingException,
        ValidationException,
    ],
    pagination: {
        inputToken: "NextToken",
        outputToken: "NextToken",
        items: "Executions",
        pageSize: "MaxResults",
    },
}));
/**
 * Lists all available tables in data exports.
 */
export const listTables = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListTablesRequest,
    output: ListTablesResponse,
    errors: [InternalServerException, ThrottlingException, ValidationException],
    pagination: {
        inputToken: "NextToken",
        outputToken: "NextToken",
        items: "Tables",
        pageSize: "MaxResults",
    },
}));
/**
 * List tags associated with an existing data export.
 */
export const listTagsForResource = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: ListTagsForResourceRequest,
    output: ListTagsForResourceResponse,
    errors: [
        AccessDeniedException,
        InternalServerException,
        ResourceNotFoundException,
        ThrottlingException,
        ValidationException,
    ],
}));
/**
 * Adds tags for an existing data export definition.
 */
export const tagResource = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: TagResourceRequest,
    output: TagResourceResponse,
    errors: [
        AccessDeniedException,
        InternalServerException,
        ResourceNotFoundException,
        ThrottlingException,
        ValidationException,
    ],
}));
/**
 * Deletes tags associated with an existing data export definition.
 */
export const untagResource = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: UntagResourceRequest,
    output: UntagResourceResponse,
    errors: [
        AccessDeniedException,
        InternalServerException,
        ResourceNotFoundException,
        ThrottlingException,
        ValidationException,
    ],
}));
/**
 * Creates a data export and specifies the data query, the delivery preference, and any optional resource tags.
 *
 * A `DataQuery` consists of both a `QueryStatement` and `TableConfigurations`.
 *
 * The `QueryStatement` is an SQL statement. Data Exports only supports a limited subset of the SQL syntax. For more information on the SQL syntax that is supported, see Data query. To view the available tables and columns, see the Data Exports table dictionary.
 *
 * The `TableConfigurations` is a collection of specified `TableProperties` for the table being queried in the `QueryStatement`. TableProperties are additional configurations you can provide to change the data and schema of a table. Each table can have different TableProperties. However, tables are not required to have any TableProperties. Each table property has a default value that it assumes if not specified. For more information on table configurations, see Data query. To view the table properties available for each table, see the Data Exports table dictionary or use the `ListTables` API to get a response of all tables and their available properties.
 */
export const createExport = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: CreateExportRequest,
    output: CreateExportResponse,
    errors: [
        AccessDeniedException,
        InternalServerException,
        ServiceQuotaExceededException,
        ThrottlingException,
        ValidationException,
    ],
}));
/**
 * Views the definition of an existing data export.
 */
export const getExport = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetExportRequest,
    output: GetExportResponse,
    errors: [
        InternalServerException,
        ResourceNotFoundException,
        ThrottlingException,
        ValidationException,
    ],
}));
/**
 * Updates an existing data export by overwriting all export parameters. All export parameters must be provided in the UpdateExport request.
 */
export const updateExport = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: UpdateExportRequest,
    output: UpdateExportResponse,
    errors: [
        InternalServerException,
        ResourceNotFoundException,
        ThrottlingException,
        ValidationException,
    ],
}));
/**
 * Deletes an existing data export.
 */
export const deleteExport = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: DeleteExportRequest,
    output: DeleteExportResponse,
    errors: [
        InternalServerException,
        ResourceNotFoundException,
        ThrottlingException,
        ValidationException,
    ],
}));
/**
 * Lists all data export definitions.
 */
export const listExports = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListExportsRequest,
    output: ListExportsResponse,
    errors: [InternalServerException, ThrottlingException, ValidationException],
    pagination: {
        inputToken: "NextToken",
        outputToken: "NextToken",
        items: "Exports",
        pageSize: "MaxResults",
    },
}));
//# sourceMappingURL=bcm-data-exports.js.map