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

package cognitoidentityprovider

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

// Adds additional user attributes to the user pool schema. Custom attributes can
// be mutable or immutable and have a custom: or dev: prefix. For more
// information, see [Custom attributes].
//
// Amazon Cognito evaluates Identity and Access Management (IAM) policies in
// requests for this API operation. For this operation, you must use IAM
// credentials to authorize requests, and you must grant yourself the corresponding
// IAM permission in a policy.
//
// # Learn more
//
// [Signing Amazon Web Services API Requests]
//
// [Using the Amazon Cognito user pools API and user pool endpoints]
//
// [Custom attributes]: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-custom-attributes
// [Using the Amazon Cognito user pools API and user pool endpoints]: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pools-API-operations.html
// [Signing Amazon Web Services API Requests]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-signing.html
func (c *Client) AddCustomAttributes(ctx context.Context, params *AddCustomAttributesInput, optFns ...func(*Options)) (*AddCustomAttributesOutput, error) {
	if params == nil {
		params = &AddCustomAttributesInput{}
	}

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

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

// Represents the request to add custom attributes.
type AddCustomAttributesInput struct {

	// An array of custom attribute names and other properties. Sets the following
	// characteristics:
	//
	// AttributeDataType The expected data type. Can be a string, a number, a date and
	// time, or a boolean.
	//
	// Mutable If true, you can grant app clients write access to the attribute value.
	// If false, the attribute value can only be set up on sign-up or administrator
	// creation of users.
	//
	// Name The attribute name. For an attribute like custom:myAttribute , enter
	// myAttribute for this field.
	//
	// Required When true, users who sign up or are created must set a value for the
	// attribute.
	//
	// NumberAttributeConstraints The minimum and maximum length of accepted values
	// for a Number -type attribute.
	//
	// StringAttributeConstraints The minimum and maximum length of accepted values
	// for a String -type attribute.
	//
	// DeveloperOnlyAttribute This legacy option creates an attribute with a dev:
	// prefix. You can only set the value of a developer-only attribute with
	// administrative IAM credentials.
	//
	// This member is required.
	CustomAttributes []types.SchemaAttributeType

	// The ID of the user pool where you want to add custom attributes.
	//
	// This member is required.
	UserPoolId *string

	noSmithyDocumentSerde
}

// Represents the response from the server for the request to add custom
// attributes.
type AddCustomAttributesOutput struct {
	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata

	noSmithyDocumentSerde
}

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