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

package cloudwatch

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

// Creates or updates an alarm mute rule.
//
// Alarm mute rules automatically mute alarm actions during predefined time
// windows. When a mute rule is active, targeted alarms continue to evaluate
// metrics and transition between states, but their configured actions (such as
// Amazon SNS notifications or Auto Scaling actions) are muted.
//
// You can create mute rules with recurring schedules using cron expressions or
// one-time mute windows using at expressions. Each mute rule can target up to 100
// specific alarms by name.
//
// If you specify a rule name that already exists, this operation updates the
// existing rule with the new configuration.
//
// # Permissions
//
// To create or update a mute rule, you must have the cloudwatch:PutAlarmMuteRule
// permission on two types of resources: the alarm mute rule resource itself, and
// each alarm that the rule targets.
//
// For example, If you want to allow a user to create mute rules that target only
// specific alarms named "WebServerCPUAlarm" and "DatabaseConnectionAlarm", you
// would create an IAM policy with one statement granting
// cloudwatch:PutAlarmMuteRule on the alarm mute rule resource (
// arn:aws:cloudwatch:[REGION]:123456789012:alarm-mute-rule:* ), and another
// statement granting cloudwatch:PutAlarmMuteRule on the targeted alarm resources (
// arn:aws:cloudwatch:[REGION]:123456789012:alarm:WebServerCPUAlarm and
// arn:aws:cloudwatch:[REGION]:123456789012:alarm:DatabaseConnectionAlarm ).
//
// You can also use IAM policy conditions to allow targeting alarms based on
// resource tags. For example, you can restrict users to create/update mute rules
// to only target alarms that have a specific tag key-value pair, such as
// Team=TeamA .
func (c *Client) PutAlarmMuteRule(ctx context.Context, params *PutAlarmMuteRuleInput, optFns ...func(*Options)) (*PutAlarmMuteRuleOutput, error) {
	if params == nil {
		params = &PutAlarmMuteRuleInput{}
	}

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

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

type PutAlarmMuteRuleInput struct {

	// The name of the alarm mute rule. This name must be unique within your Amazon
	// Web Services account and region.
	//
	// This member is required.
	Name *string

	// The configuration that defines when and how long alarms should be muted.
	//
	// This member is required.
	Rule *types.Rule

	// A description of the alarm mute rule that helps you identify its purpose.
	Description *string

	// The date and time when the mute rule expires and is no longer evaluated,
	// specified as a timestamp in ISO 8601 format (for example, 2026-12-31T23:59:59Z
	// ). After this time, the rule status becomes EXPIRED and will no longer mute the
	// targeted alarms.
	ExpireDate *time.Time

	// Specifies which alarms this rule applies to.
	MuteTargets *types.MuteTargets

	// The date and time after which the mute rule takes effect, specified as a
	// timestamp in ISO 8601 format (for example, 2026-04-15T08:00:00Z ). If not
	// specified, the mute rule takes effect immediately upon creation and the mutes
	// are applied as per the schedule expression.
	StartDate *time.Time

	// A list of key-value pairs to associate with the alarm mute rule. You can use
	// tags to categorize and manage your mute rules.
	Tags []types.Tag

	noSmithyDocumentSerde
}

type PutAlarmMuteRuleOutput struct {
	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata

	noSmithyDocumentSerde
}

func (c *Client) addOperationPutAlarmMuteRuleMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&smithyRpcv2cbor_serializeOpPutAlarmMuteRule{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&smithyRpcv2cbor_deserializeOpPutAlarmMuteRule{}, 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 = addUserAgentFeatureProtocolRPCV2CBOR(stack, options); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addOpPutAlarmMuteRuleValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "PutAlarmMuteRule"), 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
}
