// Code generated by smithy-go-codegen DO NOT EDIT.

package devopsagent

import (
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/service/devopsagent/types"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
	"time"
)

// Creates a Private Connection to a target resource.
func (c *Client) CreatePrivateConnection(ctx context.Context, params *CreatePrivateConnectionInput, optFns ...func(*Options)) (*CreatePrivateConnectionOutput, error) {
	if params == nil {
		params = &CreatePrivateConnectionInput{}
	}

	result, metadata, err := c.invokeOperation(ctx, "CreatePrivateConnection", params, optFns, c.addOperationCreatePrivateConnectionMiddlewares)
	if err != nil {
		return nil, err
	}

	out := result.(*CreatePrivateConnectionOutput)
	out.ResultMetadata = metadata
	return out, nil
}

// Input for creating a new Private Connection.
type CreatePrivateConnectionInput struct {

	// Private Connection mode configuration.
	//
	// This member is required.
	Mode types.PrivateConnectionMode

	// Unique name for this Private Connection within the account.
	//
	// This member is required.
	Name *string

	// Tags to add to the Private Connection at creation time.
	Tags map[string]string

	noSmithyDocumentSerde
}

// Output containing the newly created Private Connection summary.
type CreatePrivateConnectionOutput struct {

	// The name of the Private Connection.
	//
	// This member is required.
	Name *string

	// The status of the Private Connection.
	//
	// This member is required.
	Status types.PrivateConnectionStatus

	// The type of the Private Connection.
	//
	// This member is required.
	Type types.PrivateConnectionType

	// The expiry time of the certificate associated with the Private Connection. Only
	// present when a certificate is associated.
	CertificateExpiryTime *time.Time

	// DNS resolution mode for the Private Connection's resource gateway.
	DnsResolution types.ResourceConfigDnsResolution

	// Message describing the reason for a failed Private Connection creation, if
	// applicable.
	FailureMessage *string

	// IP address or DNS name of the target resource. Only present for service-managed
	// Private Connections.
	HostAddress *string

	// The Resource Configuration ARN. Only present for self-managed Private
	// Connections.
	ResourceConfigurationId *string

	// The service-managed Resource Gateway ARN. Only present for service-managed
	// Private Connections.
	ResourceGatewayId *string

	// Tags associated with the created Private Connection.
	Tags map[string]string

	// VPC identifier of the service-managed Resource Gateway. Only present for
	// service-managed Private Connections.
	VpcId *string

	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreatePrivateConnectionMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreatePrivateConnection{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreatePrivateConnection{}, middleware.After)
	if err != nil {
		return err
	}

	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
		return err
	}
	if err = addComputeContentLength(stack); err != nil {
		return err
	}
	if err = addResolveEndpointMiddleware(stack, options); err != nil {
		return err
	}
	if err = addComputePayloadSHA256(stack); err != nil {
		return err
	}
	if err = addRecordResponseTiming(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addEndpointPrefix_opCreatePrivateConnectionMiddleware(stack); err != nil {
		return err
	}
	if err = addOpCreatePrivateConnectionValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "CreatePrivateConnection"), middleware.Before); err != nil {
		return err
	}
	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
		return err
	}
	if err = addResponseErrorMiddleware(stack); err != nil {
		return err
	}
	if err = addRequestResponseLogging(stack, options); err != nil {
		return err
	}
	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}

type endpointPrefix_opCreatePrivateConnectionMiddleware struct {
}

func (*endpointPrefix_opCreatePrivateConnectionMiddleware) ID() string {
	return "EndpointHostPrefix"
}

func (m *endpointPrefix_opCreatePrivateConnectionMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
	out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
) {
	if smithyhttp.GetHostnameImmutable(ctx) || smithyhttp.IsEndpointHostPrefixDisabled(ctx) {
		return next.HandleFinalize(ctx, in)
	}

	req, ok := in.Request.(*smithyhttp.Request)
	if !ok {
		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
	}

	req.URL.Host = "cp." + req.URL.Host

	return next.HandleFinalize(ctx, in)
}
func addEndpointPrefix_opCreatePrivateConnectionMiddleware(stack *middleware.Stack) error {
	return stack.Finalize.Insert(&endpointPrefix_opCreatePrivateConnectionMiddleware{}, "ResolveEndpointV2", middleware.After)
}
