// 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"
	"time"
)

// Creates a new daemon in the specified cluster and capacity providers. A daemon
// deploys cross-cutting software agents such as security monitoring, telemetry,
// and logging independently across your Amazon ECS infrastructure.
//
// Amazon ECS deploys exactly one daemon task on each container instance of the
// specified capacity providers. When a container instance registers with the
// cluster, Amazon ECS automatically starts daemon tasks. Amazon ECS starts a
// daemon task before scheduling other tasks.
//
// Daemons are essential for instance health - if a daemon task stops, Amazon ECS
// automatically drains and replaces that container instance.
//
// ECS Managed Daemons is only supported for Amazon ECS Managed Instances Capacity
// Providers.
func (c *Client) CreateDaemon(ctx context.Context, params *CreateDaemonInput, optFns ...func(*Options)) (*CreateDaemonOutput, error) {
	if params == nil {
		params = &CreateDaemonInput{}
	}

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

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

type CreateDaemonInput struct {

	// The Amazon Resource Names (ARNs) of the capacity providers to associate with
	// the daemon. The daemon deploys tasks on container instances managed by these
	// capacity providers.
	//
	// This member is required.
	CapacityProviderArns []string

	// The name of the daemon. Up to 255 letters (uppercase and lowercase), numbers,
	// underscores, and hyphens are allowed.
	//
	// This member is required.
	DaemonName *string

	// The Amazon Resource Name (ARN) of the daemon task definition to use for the
	// daemon.
	//
	// This member is required.
	DaemonTaskDefinitionArn *string

	// An identifier that you provide to ensure the idempotency of the request. It
	// must be unique and is case sensitive. Up to 36 ASCII characters in the range of
	// 33-126 (inclusive) are allowed.
	ClientToken *string

	// The Amazon Resource Name (ARN) of the cluster to create the daemon in.
	ClusterArn *string

	// Optional deployment parameters that control how the daemon rolls out updates,
	// including the drain percentage, alarm-based rollback, and bake time.
	DeploymentConfiguration *types.DaemonDeploymentConfiguration

	// Specifies whether to turn on Amazon ECS managed tags for the tasks in the
	// daemon. For more information, see [Tagging your Amazon ECS resources]in the Amazon Elastic Container Service
	// Developer Guide.
	//
	// [Tagging your Amazon ECS resources]: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-using-tags.html
	EnableECSManagedTags bool

	// Determines whether the execute command functionality is turned on for the
	// daemon. If true , the execute command functionality is turned on for all tasks
	// in the daemon.
	EnableExecuteCommand bool

	// Specifies whether to propagate the tags from the daemon to the daemon tasks. If
	// you don't specify a value, the tags aren't propagated. You can only propagate
	// tags to daemon tasks during task creation. To add tags to a task after task
	// creation, use the [TagResource]API action.
	//
	// [TagResource]: https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_TagResource.html
	PropagateTags types.DaemonPropagateTags

	// The metadata that you apply to the daemon 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

	noSmithyDocumentSerde
}

type CreateDaemonOutput struct {

	// The Unix timestamp for the time when the daemon was created.
	CreatedAt *time.Time

	// The Amazon Resource Name (ARN) of the daemon.
	DaemonArn *string

	// The Amazon Resource Name (ARN) of the initial daemon deployment. This
	// deployment places daemon tasks on each container instance of the specified
	// capacity providers.
	DeploymentArn *string

	// The status of the daemon.
	Status types.DaemonStatus

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateDaemonMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
		return err
	}
	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateDaemon{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateDaemon{}, middleware.After)
	if err != nil {
		return err
	}
	if err := addProtocolFinalizerMiddlewares(stack, options, "CreateDaemon"); 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 = addOpCreateDaemonValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateDaemon(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_opCreateDaemon(region string) *awsmiddleware.RegisterServiceMetadata {
	return &awsmiddleware.RegisterServiceMetadata{
		Region:        region,
		ServiceID:     ServiceID,
		OperationName: "CreateDaemon",
	}
}
