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: "EC2 Instance Connect",
    serviceShapeName: "AWSEC2InstanceConnectService",
});
const auth = T.AwsAuthSigv4({ name: "ec2-instance-connect" });
const ver = T.ServiceVersion("2018-04-02");
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://ec2-instance-connect-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://ec2-instance-connect-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://ec2-instance-connect.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}`);
                    }
                    return err("DualStack is enabled but this partition does not support DualStack");
                }
                return e(`https://ec2-instance-connect.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}`);
            }
        }
    }
    return err("Invalid Configuration: Missing Region");
});
export const SendSerialConsoleSSHPublicKeyRequest = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    InstanceId: S.String,
    SerialPort: S.optional(S.Number),
    SSHPublicKey: S.String,
}).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "SendSerialConsoleSSHPublicKeyRequest",
});
export const SendSerialConsoleSSHPublicKeyResponse = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    RequestId: S.optional(S.String),
    Success: S.optional(S.Boolean),
})).annotate({
    identifier: "SendSerialConsoleSSHPublicKeyResponse",
});
export const SendSSHPublicKeyRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    InstanceId: S.String,
    InstanceOSUser: S.String,
    SSHPublicKey: S.String,
    AvailabilityZone: S.optional(S.String),
}).pipe(T.all(T.Http({ method: "POST", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "SendSSHPublicKeyRequest",
});
export const SendSSHPublicKeyResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    RequestId: S.optional(S.String),
    Success: S.optional(S.Boolean),
})).annotate({
    identifier: "SendSSHPublicKeyResponse",
});
//# Errors
export class AuthException extends S.TaggedErrorClass()("AuthException", { Message: S.optional(S.String) }, T.AwsQueryError({ code: "Forbidden", httpResponseCode: 403 })).pipe(C.withAuthError) {
}
export class EC2InstanceNotFoundException extends S.TaggedErrorClass()("EC2InstanceNotFoundException", { Message: S.optional(S.String) }, T.AwsQueryError({ code: "EC2InstanceNotFound", httpResponseCode: 404 })).pipe(C.withBadRequestError) {
}
export class EC2InstanceStateInvalidException extends S.TaggedErrorClass()("EC2InstanceStateInvalidException", { Message: S.optional(S.String) }, T.AwsQueryError({ code: "EC2InstanceStateInvalid", httpResponseCode: 400 })).pipe(C.withBadRequestError) {
}
export class EC2InstanceTypeInvalidException extends S.TaggedErrorClass()("EC2InstanceTypeInvalidException", { Message: S.optional(S.String) }, T.AwsQueryError({ code: "EC2InstanceTypeInvalid", httpResponseCode: 400 })).pipe(C.withBadRequestError) {
}
export class EC2InstanceUnavailableException extends S.TaggedErrorClass()("EC2InstanceUnavailableException", { Message: S.optional(S.String) }, T.AwsQueryError({ code: "EC2InstanceUnavailable", httpResponseCode: 503 })).pipe(C.withServerError) {
}
export class InvalidArgsException extends S.TaggedErrorClass()("InvalidArgsException", { Message: S.optional(S.String) }, T.AwsQueryError({ code: "InvalidArguments", httpResponseCode: 400 })).pipe(C.withBadRequestError) {
}
export class SerialConsoleAccessDisabledException extends S.TaggedErrorClass()("SerialConsoleAccessDisabledException", { Message: S.optional(S.String) }, T.AwsQueryError({
    code: "SerialConsoleAccessDisabled",
    httpResponseCode: 403,
})).pipe(C.withAuthError) {
}
export class SerialConsoleSessionLimitExceededException extends S.TaggedErrorClass()("SerialConsoleSessionLimitExceededException", { Message: S.optional(S.String) }, T.AwsQueryError({
    code: "SerialConsoleSessionLimitExceeded",
    httpResponseCode: 400,
})).pipe(C.withBadRequestError) {
}
export class SerialConsoleSessionUnavailableException extends S.TaggedErrorClass()("SerialConsoleSessionUnavailableException", { Message: S.optional(S.String) }, T.AwsQueryError({
    code: "SerialConsoleSessionUnavailable",
    httpResponseCode: 500,
})).pipe(C.withServerError) {
}
export class SerialConsoleSessionUnsupportedException extends S.TaggedErrorClass()("SerialConsoleSessionUnsupportedException", { Message: S.optional(S.String) }, T.AwsQueryError({
    code: "SerialConsoleSessionUnsupported",
    httpResponseCode: 400,
})).pipe(C.withBadRequestError) {
}
export class ServiceException extends S.TaggedErrorClass()("ServiceException", { Message: S.optional(S.String) }, T.AwsQueryError({ code: "InternalServerError", httpResponseCode: 500 })).pipe(C.withServerError) {
}
export class ThrottlingException extends S.TaggedErrorClass()("ThrottlingException", { Message: S.optional(S.String) }, T.AwsQueryError({ code: "TooManyRequests", httpResponseCode: 429 })).pipe(C.withThrottlingError) {
}
/**
 * Pushes an SSH public key to the specified EC2 instance. The key remains for 60
 * seconds, which gives you 60 seconds to establish a serial console connection to the
 * instance using SSH. For more information, see EC2 Serial Console in
 * the *Amazon EC2 User Guide*.
 */
export const sendSerialConsoleSSHPublicKey = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: SendSerialConsoleSSHPublicKeyRequest,
    output: SendSerialConsoleSSHPublicKeyResponse,
    errors: [
        AuthException,
        EC2InstanceNotFoundException,
        EC2InstanceStateInvalidException,
        EC2InstanceTypeInvalidException,
        EC2InstanceUnavailableException,
        InvalidArgsException,
        SerialConsoleAccessDisabledException,
        SerialConsoleSessionLimitExceededException,
        SerialConsoleSessionUnavailableException,
        SerialConsoleSessionUnsupportedException,
        ServiceException,
        ThrottlingException,
    ],
}));
/**
 * Pushes an SSH public key to the specified EC2 instance for use by the specified user.
 * The key remains for 60 seconds. For more information, see Connect to
 * your Linux instance using EC2 Instance Connect in the Amazon EC2
 * User Guide.
 */
export const sendSSHPublicKey = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: SendSSHPublicKeyRequest,
    output: SendSSHPublicKeyResponse,
    errors: [
        AuthException,
        EC2InstanceNotFoundException,
        EC2InstanceStateInvalidException,
        EC2InstanceUnavailableException,
        InvalidArgsException,
        ServiceException,
        ThrottlingException,
    ],
}));
//# sourceMappingURL=ec2-instance-connect.js.map