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

package codeartifact

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

//	Sets a resource policy on a domain that specifies permissions to access it.
//
// When you call PutDomainPermissionsPolicy , the resource policy on the domain is
// ignored when evaluting permissions. This ensures that the owner of a domain
// cannot lock themselves out of the domain, which would prevent them from being
// able to update the resource policy.
func (c *Client) PutDomainPermissionsPolicy(ctx context.Context, params *PutDomainPermissionsPolicyInput, optFns ...func(*Options)) (*PutDomainPermissionsPolicyOutput, error) {
	if params == nil {
		params = &PutDomainPermissionsPolicyInput{}
	}

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

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

type PutDomainPermissionsPolicyInput struct {

	//  The name of the domain on which to set the resource policy.
	//
	// This member is required.
	Domain *string

	//  A valid displayable JSON Aspen policy string to be set as the access control
	// resource policy on the provided domain.
	//
	// This member is required.
	PolicyDocument *string

	//  The 12-digit account number of the Amazon Web Services account that owns the
	// domain. It does not include dashes or spaces.
	DomainOwner *string

	//  The current revision of the resource policy to be set. This revision is used
	// for optimistic locking, which prevents others from overwriting your changes to
	// the domain's resource policy.
	PolicyRevision *string

	noSmithyDocumentSerde
}

type PutDomainPermissionsPolicyOutput struct {

	//  The resource policy that was set after processing the request.
	Policy *types.ResourcePolicy

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationPutDomainPermissionsPolicyMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpPutDomainPermissionsPolicy{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpPutDomainPermissionsPolicy{}, 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 = addOpPutDomainPermissionsPolicyValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "PutDomainPermissionsPolicy"), 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
}
