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

package ecs

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

// Registers a new daemon task definition from the supplied family and
// containerDefinitions . Optionally, you can add data volumes to your containers
// with the volumes parameter. For more information, see [Daemon task definitions] in the Amazon Elastic
// Container Service Developer Guide.
//
// A daemon task definition is a template that describes the containers that form
// a daemon. Daemons deploy cross-cutting software agents such as security
// monitoring, telemetry, and logging across your Amazon ECS infrastructure.
//
// Each time you call RegisterDaemonTaskDefinition , a new revision of the daemon
// task definition is created. You can't modify a revision after you register it.
//
// [Daemon task definitions]: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/daemon-task-definitions.html
func (c *Client) RegisterDaemonTaskDefinition(ctx context.Context, params *RegisterDaemonTaskDefinitionInput, optFns ...func(*Options)) (*RegisterDaemonTaskDefinitionOutput, error) {
	if params == nil {
		params = &RegisterDaemonTaskDefinitionInput{}
	}

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

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

type RegisterDaemonTaskDefinitionInput struct {

	// A list of container definitions in JSON format that describe the containers
	// that make up your daemon task.
	//
	// This member is required.
	ContainerDefinitions []types.DaemonContainerDefinition

	// You must specify a family for a daemon task definition. This family is used as
	// a name for your daemon task definition. Up to 255 letters (uppercase and
	// lowercase), numbers, underscores, and hyphens are allowed.
	//
	// This member is required.
	Family *string

	// The number of CPU units used by the daemon task. It can be expressed as an
	// integer using CPU units (for example, 1024 ).
	Cpu *string

	// The Amazon Resource Name (ARN) of the task execution role that grants the
	// Amazon ECS container agent permission to make Amazon Web Services API calls on
	// your behalf. The task execution role is required for daemon tasks that pull
	// container images from Amazon ECR or send container logs to CloudWatch.
	ExecutionRoleArn *string

	// The amount of memory (in MiB) used by the daemon task. It can be expressed as
	// an integer using MiB (for example, 1024 ).
	Memory *string

	// The metadata that you apply to the daemon task definition to help you
	// categorize and organize them. Each tag consists of a key and an optional value.
	// You define both of them.
	//
	// The following basic restrictions apply to tags:
	//
	//   - Maximum number of tags per resource - 50
	//
	//   - For each resource, each tag key must be unique, and each tag key can have
	//   only one value.
	//
	//   - Maximum key length - 128 Unicode characters in UTF-8
	//
	//   - Maximum value length - 256 Unicode characters in UTF-8
	//
	//   - If your tagging schema is used across multiple services and resources,
	//   remember that other services may have restrictions on allowed characters.
	//   Generally allowed characters are: letters, numbers, and spaces representable in
	//   UTF-8, and the following characters: + - = . _ : / @.
	//
	//   - Tag keys and values are case-sensitive.
	//
	//   - Do not use aws: , AWS: , or any upper or lowercase combination of such as a
	//   prefix for either keys or values as it is reserved for Amazon Web Services use.
	//   You cannot edit or delete tag keys or values with this prefix. Tags with this
	//   prefix do not count against your tags per resource limit.
	Tags []types.Tag

	// The short name or full Amazon Resource Name (ARN) of the IAM role that
	// containers in this daemon task can assume. All containers in this daemon task
	// are granted the permissions that are specified in this role.
	TaskRoleArn *string

	// A list of volume definitions in JSON format that containers in your daemon task
	// can use.
	Volumes []types.DaemonVolume

	noSmithyDocumentSerde
}

type RegisterDaemonTaskDefinitionOutput struct {

	// The full Amazon Resource Name (ARN) of the registered daemon task definition.
	DaemonTaskDefinitionArn *string

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationRegisterDaemonTaskDefinitionMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
		return err
	}
	err = stack.Serialize.Add(&awsAwsjson11_serializeOpRegisterDaemonTaskDefinition{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpRegisterDaemonTaskDefinition{}, middleware.After)
	if err != nil {
		return err
	}
	if err := addProtocolFinalizerMiddlewares(stack, options, "RegisterDaemonTaskDefinition"); err != nil {
		return fmt.Errorf("add protocol finalizers: %v", err)
	}

	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
		return err
	}
	if err = addSetLoggerMiddleware(stack, options); err != nil {
		return err
	}
	if err = addClientRequestID(stack); 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 = addRetry(stack, options, c); err != nil {
		return err
	}
	if err = addRawResponseToMetadata(stack); err != nil {
		return err
	}
	if err = addRecordResponseTiming(stack); err != nil {
		return err
	}
	if err = addSpanRetryLoop(stack, options); err != nil {
		return err
	}
	if err = addClientUserAgent(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 = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
		return err
	}
	if err = addUserAgentRetryMode(stack, options); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addOpRegisterDaemonTaskDefinitionValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opRegisterDaemonTaskDefinition(options.Region), middleware.Before); err != nil {
		return err
	}
	if err = addRecursionDetection(stack); 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 = addInterceptBeforeRetryLoop(stack, options); err != nil {
		return err
	}
	if err = addInterceptAttempt(stack, options); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}

func newServiceMetadataMiddleware_opRegisterDaemonTaskDefinition(region string) *awsmiddleware.RegisterServiceMetadata {
	return &awsmiddleware.RegisterServiceMetadata{
		Region:        region,
		ServiceID:     ServiceID,
		OperationName: "RegisterDaemonTaskDefinition",
	}
}
