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: "MigrationHub Config",
    serviceShapeName: "AWSMigrationHubMultiAccountService",
});
const auth = T.AwsAuthSigv4({ name: "mgh" });
const ver = T.ServiceVersion("2019-06-30");
const proto = T.AwsProtocolsAwsJson1_1();
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://migrationhub-config-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://migrationhub-config-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://migrationhub-config.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}`);
                    }
                    return err("DualStack is enabled but this partition does not support DualStack");
                }
                return e(`https://migrationhub-config.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}`);
            }
        }
    }
    return err("Invalid Configuration: Missing Region");
});
export const TargetType = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const Target = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Type: TargetType, Id: S.optional(S.String) })).annotate({ identifier: "Target" });
export const CreateHomeRegionControlRequest = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    HomeRegion: S.String,
    Target: Target,
    DryRun: S.optional(S.Boolean),
}).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "CreateHomeRegionControlRequest",
});
export const HomeRegionControl = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ControlId: S.optional(S.String),
    HomeRegion: S.optional(S.String),
    Target: S.optional(Target),
    RequestedTime: S.optional(S.Date.pipe(T.TimestampFormat("epoch-seconds"))),
})).annotate({
    identifier: "HomeRegionControl",
});
export const CreateHomeRegionControlResult = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ HomeRegionControl: S.optional(HomeRegionControl) })).annotate({
    identifier: "CreateHomeRegionControlResult",
});
export const DeleteHomeRegionControlRequest = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ ControlId: S.String }).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "DeleteHomeRegionControlRequest",
});
export const DeleteHomeRegionControlResult = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({})).annotate({
    identifier: "DeleteHomeRegionControlResult",
});
export const DescribeHomeRegionControlsRequest = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ControlId: S.optional(S.String),
    HomeRegion: S.optional(S.String),
    Target: S.optional(Target),
    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: "DescribeHomeRegionControlsRequest",
});
export const HomeRegionControls = 
/*@__PURE__*/ /*#__PURE__*/ S.Array(HomeRegionControl);
export const DescribeHomeRegionControlsResult = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    HomeRegionControls: S.optional(HomeRegionControls),
    NextToken: S.optional(S.String),
})).annotate({
    identifier: "DescribeHomeRegionControlsResult",
});
export const GetHomeRegionRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({}).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "GetHomeRegionRequest",
});
export const GetHomeRegionResult = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ HomeRegion: S.optional(S.String) })).annotate({
    identifier: "GetHomeRegionResult",
});
//# Errors
export class AccessDeniedException extends S.TaggedErrorClass()("AccessDeniedException", { Message: S.optional(S.String) }).pipe(C.withAuthError) {
}
export class DryRunOperation extends S.TaggedErrorClass()("DryRunOperation", { Message: S.optional(S.String) }) {
}
export class InternalServerError extends S.TaggedErrorClass()("InternalServerError", { Message: S.optional(S.String) }) {
}
export class InvalidInputException extends S.TaggedErrorClass()("InvalidInputException", { Message: S.optional(S.String) }) {
}
export class ServiceUnavailableException extends S.TaggedErrorClass()("ServiceUnavailableException", { Message: S.optional(S.String) }).pipe(C.withServerError) {
}
export class ThrottlingException extends S.TaggedErrorClass()("ThrottlingException", {
    Message: S.String,
    RetryAfterSeconds: S.optional(S.Number).pipe(T.HttpHeader("Retry-After")),
}).pipe(C.withThrottlingError) {
}
/**
 * This API sets up the home region for the calling account only.
 */
export const createHomeRegionControl = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: CreateHomeRegionControlRequest,
    output: CreateHomeRegionControlResult,
    errors: [
        AccessDeniedException,
        DryRunOperation,
        InternalServerError,
        InvalidInputException,
        ServiceUnavailableException,
        ThrottlingException,
    ],
}));
/**
 * This operation deletes the home region configuration for the calling account. The operation does not delete discovery or migration tracking data in the home region.
 */
export const deleteHomeRegionControl = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: DeleteHomeRegionControlRequest,
    output: DeleteHomeRegionControlResult,
    errors: [
        AccessDeniedException,
        InternalServerError,
        InvalidInputException,
        ServiceUnavailableException,
        ThrottlingException,
    ],
}));
/**
 * This API permits filtering on the `ControlId` and `HomeRegion`
 * fields.
 */
export const describeHomeRegionControls = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: DescribeHomeRegionControlsRequest,
    output: DescribeHomeRegionControlsResult,
    errors: [
        AccessDeniedException,
        InternalServerError,
        InvalidInputException,
        ServiceUnavailableException,
        ThrottlingException,
    ],
    pagination: {
        inputToken: "NextToken",
        outputToken: "NextToken",
        pageSize: "MaxResults",
    },
}));
/**
 * Returns the calling account’s home region, if configured. This API is used by other AWS
 * services to determine the regional endpoint for calling AWS Application Discovery Service and
 * Migration Hub. You must call `GetHomeRegion` at least once before you call any
 * other AWS Application Discovery Service and AWS Migration Hub APIs, to obtain the account's
 * Migration Hub home region.
 */
export const getHomeRegion = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetHomeRegionRequest,
    output: GetHomeRegionResult,
    errors: [
        AccessDeniedException,
        InternalServerError,
        InvalidInputException,
        ServiceUnavailableException,
        ThrottlingException,
    ],
}));
//# sourceMappingURL=migrationhub-config.js.map