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: "ControlCatalog",
    serviceShapeName: "ControlCatalog",
});
const auth = T.AwsAuthSigv4({ name: "controlcatalog" });
const ver = T.ServiceVersion("2018-05-10");
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://controlcatalog-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://controlcatalog-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://controlcatalog.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}`);
                    }
                    return err("DualStack is enabled but this partition does not support DualStack");
                }
                return e(`https://controlcatalog.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}`);
            }
        }
    }
    return err("Invalid Configuration: Missing Region");
});
export const ControlArnFilterList = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.String);
export const CommonControlArnFilterList = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.String);
export const MappingType = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const MappingTypeFilterList = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(MappingType);
export const ControlMappingFilter = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ControlArns: S.optional(ControlArnFilterList),
    CommonControlArns: S.optional(CommonControlArnFilterList),
    MappingTypes: S.optional(MappingTypeFilterList),
})).annotate({
    identifier: "ControlMappingFilter",
});
export const ListControlMappingsRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    NextToken: S.optional(S.String).pipe(T.HttpQuery("nextToken")),
    MaxResults: S.optional(S.Number).pipe(T.HttpQuery("maxResults")),
    Filter: S.optional(ControlMappingFilter),
}).pipe(T.all(T.Http({ method: "POST", uri: "/list-control-mappings" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ListControlMappingsRequest",
});
export const FrameworkMappingDetails = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Name: S.String, Item: S.String })).annotate({
    identifier: "FrameworkMappingDetails",
});
export const CommonControlMappingDetails = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ CommonControlArn: S.String })).annotate({
    identifier: "CommonControlMappingDetails",
});
export const ControlRelationType = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const RelatedControlMappingDetails = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ControlArn: S.optional(S.String),
    RelationType: ControlRelationType,
})).annotate({
    identifier: "RelatedControlMappingDetails",
});
export const Mapping = /*@__PURE__*/ /*#__PURE__*/ S.Union([
    S.Struct({ Framework: FrameworkMappingDetails }),
    S.Struct({ CommonControl: CommonControlMappingDetails }),
    S.Struct({ RelatedControl: RelatedControlMappingDetails }),
]);
export const ControlMapping = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ControlArn: S.String,
    MappingType: MappingType,
    Mapping: Mapping,
})).annotate({ identifier: "ControlMapping" });
export const ControlMappings = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(ControlMapping);
export const ListControlMappingsResponse = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ControlMappings: ControlMappings,
    NextToken: S.optional(S.String),
})).annotate({
    identifier: "ListControlMappingsResponse",
});
export const ObjectiveResourceFilter = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Arn: S.optional(S.String) })).annotate({
    identifier: "ObjectiveResourceFilter",
});
export const ObjectiveResourceFilterList = /*@__PURE__*/ /*#__PURE__*/ S.Array(ObjectiveResourceFilter);
export const CommonControlFilter = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Objectives: S.optional(ObjectiveResourceFilterList) })).annotate({
    identifier: "CommonControlFilter",
});
export const ListCommonControlsRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    MaxResults: S.optional(S.Number).pipe(T.HttpQuery("maxResults")),
    NextToken: S.optional(S.String).pipe(T.HttpQuery("nextToken")),
    CommonControlFilter: S.optional(CommonControlFilter),
}).pipe(T.all(T.Http({ method: "POST", uri: "/common-controls" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ListCommonControlsRequest",
});
export const AssociatedDomainSummary = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Arn: S.optional(S.String), Name: S.optional(S.String) })).annotate({
    identifier: "AssociatedDomainSummary",
});
export const AssociatedObjectiveSummary = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Arn: S.optional(S.String), Name: S.optional(S.String) })).annotate({
    identifier: "AssociatedObjectiveSummary",
});
export const CommonControlSummary = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Arn: S.String,
    Name: S.String,
    Description: S.String,
    Domain: AssociatedDomainSummary,
    Objective: AssociatedObjectiveSummary,
    CreateTime: S.Date.pipe(T.TimestampFormat("epoch-seconds")),
    LastUpdateTime: S.Date.pipe(T.TimestampFormat("epoch-seconds")),
})).annotate({
    identifier: "CommonControlSummary",
});
export const CommonControlSummaryList = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(CommonControlSummary);
export const ListCommonControlsResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    CommonControls: CommonControlSummaryList,
    NextToken: S.optional(S.String),
})).annotate({
    identifier: "ListCommonControlsResponse",
});
export const GetControlRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ControlArn: S.String }).pipe(T.all(T.Http({ method: "POST", uri: "/get-control" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "GetControlRequest",
});
export const ControlAliases = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.String);
export const ControlBehavior = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const ControlSeverity = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const ControlScope = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const DeployableRegions = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.String);
export const RegionConfiguration = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Scope: ControlScope,
    DeployableRegions: S.optional(DeployableRegions),
})).annotate({
    identifier: "RegionConfiguration",
});
export const ImplementationDetails = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Type: S.String, Identifier: S.optional(S.String) })).annotate({
    identifier: "ImplementationDetails",
});
export const ControlParameter = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Name: S.String })).annotate({
    identifier: "ControlParameter",
});
export const ControlParameters = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(ControlParameter);
export const GovernedResources = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.String);
export const GetControlResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Arn: S.String,
    Aliases: S.optional(ControlAliases),
    Name: S.String,
    Description: S.String,
    Behavior: ControlBehavior,
    Severity: S.optional(ControlSeverity),
    RegionConfiguration: RegionConfiguration,
    Implementation: S.optional(ImplementationDetails),
    Parameters: S.optional(ControlParameters),
    CreateTime: S.optional(S.Date.pipe(T.TimestampFormat("epoch-seconds"))),
    GovernedResources: S.optional(GovernedResources),
})).annotate({
    identifier: "GetControlResponse",
});
export const ImplementationTypeFilterList = /*@__PURE__*/ /*#__PURE__*/ S.Array(S.String);
export const ImplementationIdentifierFilterList = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(S.String);
export const ImplementationFilter = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Types: S.optional(ImplementationTypeFilterList),
    Identifiers: S.optional(ImplementationIdentifierFilterList),
})).annotate({
    identifier: "ImplementationFilter",
});
export const ControlFilter = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Implementations: S.optional(ImplementationFilter) })).annotate({ identifier: "ControlFilter" });
export const ListControlsRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    NextToken: S.optional(S.String).pipe(T.HttpQuery("nextToken")),
    MaxResults: S.optional(S.Number).pipe(T.HttpQuery("maxResults")),
    Filter: S.optional(ControlFilter),
}).pipe(T.all(T.Http({ method: "POST", uri: "/list-controls" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ListControlsRequest",
});
export const ImplementationSummary = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Type: S.String, Identifier: S.optional(S.String) })).annotate({
    identifier: "ImplementationSummary",
});
export const ControlSummary = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Arn: S.String,
    Aliases: S.optional(ControlAliases),
    Name: S.String,
    Description: S.String,
    Behavior: S.optional(ControlBehavior),
    Severity: S.optional(ControlSeverity),
    Implementation: S.optional(ImplementationSummary),
    CreateTime: S.optional(S.Date.pipe(T.TimestampFormat("epoch-seconds"))),
    GovernedResources: S.optional(GovernedResources),
})).annotate({ identifier: "ControlSummary" });
export const Controls = /*@__PURE__*/ /*#__PURE__*/ S.Array(ControlSummary);
export const ListControlsResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Controls: Controls, NextToken: S.optional(S.String) })).annotate({
    identifier: "ListControlsResponse",
});
export const ListDomainsRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    MaxResults: S.optional(S.Number).pipe(T.HttpQuery("maxResults")),
    NextToken: S.optional(S.String).pipe(T.HttpQuery("nextToken")),
}).pipe(T.all(T.Http({ method: "POST", uri: "/domains" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ListDomainsRequest",
});
export const DomainSummary = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Arn: S.String,
    Name: S.String,
    Description: S.String,
    CreateTime: S.Date.pipe(T.TimestampFormat("epoch-seconds")),
    LastUpdateTime: S.Date.pipe(T.TimestampFormat("epoch-seconds")),
})).annotate({ identifier: "DomainSummary" });
export const DomainSummaryList = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(DomainSummary);
export const ListDomainsResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Domains: DomainSummaryList, NextToken: S.optional(S.String) })).annotate({
    identifier: "ListDomainsResponse",
});
export const DomainResourceFilter = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Arn: S.optional(S.String) })).annotate({
    identifier: "DomainResourceFilter",
});
export const DomainResourceFilterList = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(DomainResourceFilter);
export const ObjectiveFilter = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Domains: S.optional(DomainResourceFilterList) })).annotate({
    identifier: "ObjectiveFilter",
});
export const ListObjectivesRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    MaxResults: S.optional(S.Number).pipe(T.HttpQuery("maxResults")),
    NextToken: S.optional(S.String).pipe(T.HttpQuery("nextToken")),
    ObjectiveFilter: S.optional(ObjectiveFilter),
}).pipe(T.all(T.Http({ method: "POST", uri: "/objectives" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ListObjectivesRequest",
});
export const ObjectiveSummary = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Arn: S.String,
    Name: S.String,
    Description: S.String,
    Domain: AssociatedDomainSummary,
    CreateTime: S.Date.pipe(T.TimestampFormat("epoch-seconds")),
    LastUpdateTime: S.Date.pipe(T.TimestampFormat("epoch-seconds")),
})).annotate({
    identifier: "ObjectiveSummary",
});
export const ObjectiveSummaryList = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(ObjectiveSummary);
export const ListObjectivesResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Objectives: ObjectiveSummaryList,
    NextToken: S.optional(S.String),
})).annotate({
    identifier: "ListObjectivesResponse",
});
//# Errors
export class AccessDeniedException extends S.TaggedErrorClass()("AccessDeniedException", { Message: S.optional(S.String) }).pipe(C.withAuthError) {
}
export class InternalServerException extends S.TaggedErrorClass()("InternalServerException", { Message: S.optional(S.String) }, T.Retryable()).pipe(C.withServerError, C.withRetryableError) {
}
export class ThrottlingException extends S.TaggedErrorClass()("ThrottlingException", { Message: S.optional(S.String) }, T.Retryable({ throttling: true })).pipe(C.withThrottlingError, C.withRetryableError) {
}
export class ValidationException extends S.TaggedErrorClass()("ValidationException", { Message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class ResourceNotFoundException extends S.TaggedErrorClass()("ResourceNotFoundException", { Message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
/**
 * Returns a paginated list of control mappings from the Control Catalog. Control mappings show relationships between controls and other entities, such as common controls or compliance frameworks.
 */
export const listControlMappings = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListControlMappingsRequest,
    output: ListControlMappingsResponse,
    errors: [
        AccessDeniedException,
        InternalServerException,
        ThrottlingException,
        ValidationException,
    ],
    pagination: {
        inputToken: "NextToken",
        outputToken: "NextToken",
        items: "ControlMappings",
        pageSize: "MaxResults",
    },
}));
/**
 * Returns a paginated list of common controls from the Amazon Web Services Control Catalog.
 *
 * You can apply an optional filter to see common controls that have a specific objective. If you don’t provide a filter, the operation returns all common controls.
 */
export const listCommonControls = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListCommonControlsRequest,
    output: ListCommonControlsResponse,
    errors: [
        AccessDeniedException,
        InternalServerException,
        ThrottlingException,
        ValidationException,
    ],
    pagination: {
        inputToken: "NextToken",
        outputToken: "NextToken",
        items: "CommonControls",
        pageSize: "MaxResults",
    },
}));
/**
 * Returns details about a specific control, most notably a list of Amazon Web Services Regions where this control is supported. Input a value for the *ControlArn* parameter, in ARN form. `GetControl` accepts *controltower* or *controlcatalog* control ARNs as input. Returns a *controlcatalog* ARN format.
 *
 * In the API response, controls that have the value `GLOBAL` in the `Scope` field do not show the `DeployableRegions` field, because it does not apply. Controls that have the value `REGIONAL` in the `Scope` field return a value for the `DeployableRegions` field, as shown in the example.
 */
export const getControl = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetControlRequest,
    output: GetControlResponse,
    errors: [
        AccessDeniedException,
        InternalServerException,
        ResourceNotFoundException,
        ThrottlingException,
        ValidationException,
    ],
}));
/**
 * Returns a paginated list of all available controls in the Control Catalog library. Allows you to discover available controls. The list of controls is given as structures of type *controlSummary*. The ARN is returned in the global *controlcatalog* format, as shown in the examples.
 */
export const listControls = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListControlsRequest,
    output: ListControlsResponse,
    errors: [
        AccessDeniedException,
        InternalServerException,
        ThrottlingException,
        ValidationException,
    ],
    pagination: {
        inputToken: "NextToken",
        outputToken: "NextToken",
        items: "Controls",
        pageSize: "MaxResults",
    },
}));
/**
 * Returns a paginated list of domains from the Control Catalog.
 */
export const listDomains = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListDomainsRequest,
    output: ListDomainsResponse,
    errors: [
        AccessDeniedException,
        InternalServerException,
        ThrottlingException,
        ValidationException,
    ],
    pagination: {
        inputToken: "NextToken",
        outputToken: "NextToken",
        items: "Domains",
        pageSize: "MaxResults",
    },
}));
/**
 * Returns a paginated list of objectives from the Control Catalog.
 *
 * You can apply an optional filter to see the objectives that belong to a specific domain. If you don’t provide a filter, the operation returns all objectives.
 */
export const listObjectives = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListObjectivesRequest,
    output: ListObjectivesResponse,
    errors: [
        AccessDeniedException,
        InternalServerException,
        ThrottlingException,
        ValidationException,
    ],
    pagination: {
        inputToken: "NextToken",
        outputToken: "NextToken",
        items: "Objectives",
        pageSize: "MaxResults",
    },
}));
//# sourceMappingURL=controlcatalog.js.map