// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.

package ssm

import (
	"context"
	"fmt"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/internal/awsutil"
)

// Please also see https://docs.aws.amazon.com/goto/WebAPI/ssm-2014-11-06/RegisterTargetWithMaintenanceWindowRequest
type RegisterTargetWithMaintenanceWindowInput struct {
	_ struct{} `type:"structure"`

	// User-provided idempotency token.
	ClientToken *string `min:"1" type:"string" idempotencyToken:"true"`

	// An optional description for the target.
	Description *string `min:"1" type:"string"`

	// An optional name for the target.
	Name *string `min:"3" type:"string"`

	// User-provided value that will be included in any CloudWatch events raised
	// while running tasks for these targets in this Maintenance Window.
	OwnerInformation *string `min:"1" type:"string"`

	// The type of target being registered with the Maintenance Window.
	//
	// ResourceType is a required field
	ResourceType MaintenanceWindowResourceType `type:"string" required:"true" enum:"true"`

	// The targets (either instances or tags).
	//
	// Specify instances using the following format:
	//
	// Key=InstanceIds,Values=<instance-id-1>,<instance-id-2>
	//
	// Specify tags using either of the following formats:
	//
	// Key=tag:<tag-key>,Values=<tag-value-1>,<tag-value-2>
	//
	// Key=tag-key,Values=<tag-key-1>,<tag-key-2>
	//
	// Targets is a required field
	Targets []Target `type:"list" required:"true"`

	// The ID of the Maintenance Window the target should be registered with.
	//
	// WindowId is a required field
	WindowId *string `min:"20" type:"string" required:"true"`
}

// String returns the string representation
func (s RegisterTargetWithMaintenanceWindowInput) String() string {
	return awsutil.Prettify(s)
}

// Validate inspects the fields of the type to determine if they are valid.
func (s *RegisterTargetWithMaintenanceWindowInput) Validate() error {
	invalidParams := aws.ErrInvalidParams{Context: "RegisterTargetWithMaintenanceWindowInput"}
	if s.ClientToken != nil && len(*s.ClientToken) < 1 {
		invalidParams.Add(aws.NewErrParamMinLen("ClientToken", 1))
	}
	if s.Description != nil && len(*s.Description) < 1 {
		invalidParams.Add(aws.NewErrParamMinLen("Description", 1))
	}
	if s.Name != nil && len(*s.Name) < 3 {
		invalidParams.Add(aws.NewErrParamMinLen("Name", 3))
	}
	if s.OwnerInformation != nil && len(*s.OwnerInformation) < 1 {
		invalidParams.Add(aws.NewErrParamMinLen("OwnerInformation", 1))
	}
	if len(s.ResourceType) == 0 {
		invalidParams.Add(aws.NewErrParamRequired("ResourceType"))
	}

	if s.Targets == nil {
		invalidParams.Add(aws.NewErrParamRequired("Targets"))
	}

	if s.WindowId == nil {
		invalidParams.Add(aws.NewErrParamRequired("WindowId"))
	}
	if s.WindowId != nil && len(*s.WindowId) < 20 {
		invalidParams.Add(aws.NewErrParamMinLen("WindowId", 20))
	}
	if s.Targets != nil {
		for i, v := range s.Targets {
			if err := v.Validate(); err != nil {
				invalidParams.AddNested(fmt.Sprintf("%s[%v]", "Targets", i), err.(aws.ErrInvalidParams))
			}
		}
	}

	if invalidParams.Len() > 0 {
		return invalidParams
	}
	return nil
}

// Please also see https://docs.aws.amazon.com/goto/WebAPI/ssm-2014-11-06/RegisterTargetWithMaintenanceWindowResult
type RegisterTargetWithMaintenanceWindowOutput struct {
	_ struct{} `type:"structure"`

	// The ID of the target definition in this Maintenance Window.
	WindowTargetId *string `min:"36" type:"string"`
}

// String returns the string representation
func (s RegisterTargetWithMaintenanceWindowOutput) String() string {
	return awsutil.Prettify(s)
}

const opRegisterTargetWithMaintenanceWindow = "RegisterTargetWithMaintenanceWindow"

// RegisterTargetWithMaintenanceWindowRequest returns a request value for making API operation for
// Amazon Simple Systems Manager (SSM).
//
// Registers a target with a Maintenance Window.
//
//    // Example sending a request using RegisterTargetWithMaintenanceWindowRequest.
//    req := client.RegisterTargetWithMaintenanceWindowRequest(params)
//    resp, err := req.Send(context.TODO())
//    if err == nil {
//        fmt.Println(resp)
//    }
//
// Please also see https://docs.aws.amazon.com/goto/WebAPI/ssm-2014-11-06/RegisterTargetWithMaintenanceWindow
func (c *Client) RegisterTargetWithMaintenanceWindowRequest(input *RegisterTargetWithMaintenanceWindowInput) RegisterTargetWithMaintenanceWindowRequest {
	op := &aws.Operation{
		Name:       opRegisterTargetWithMaintenanceWindow,
		HTTPMethod: "POST",
		HTTPPath:   "/",
	}

	if input == nil {
		input = &RegisterTargetWithMaintenanceWindowInput{}
	}

	req := c.newRequest(op, input, &RegisterTargetWithMaintenanceWindowOutput{})
	return RegisterTargetWithMaintenanceWindowRequest{Request: req, Input: input, Copy: c.RegisterTargetWithMaintenanceWindowRequest}
}

// RegisterTargetWithMaintenanceWindowRequest is the request type for the
// RegisterTargetWithMaintenanceWindow API operation.
type RegisterTargetWithMaintenanceWindowRequest struct {
	*aws.Request
	Input *RegisterTargetWithMaintenanceWindowInput
	Copy  func(*RegisterTargetWithMaintenanceWindowInput) RegisterTargetWithMaintenanceWindowRequest
}

// Send marshals and sends the RegisterTargetWithMaintenanceWindow API request.
func (r RegisterTargetWithMaintenanceWindowRequest) Send(ctx context.Context) (*RegisterTargetWithMaintenanceWindowResponse, error) {
	r.Request.SetContext(ctx)
	err := r.Request.Send()
	if err != nil {
		return nil, err
	}

	resp := &RegisterTargetWithMaintenanceWindowResponse{
		RegisterTargetWithMaintenanceWindowOutput: r.Request.Data.(*RegisterTargetWithMaintenanceWindowOutput),
		response: &aws.Response{Request: r.Request},
	}

	return resp, nil
}

// RegisterTargetWithMaintenanceWindowResponse is the response type for the
// RegisterTargetWithMaintenanceWindow API operation.
type RegisterTargetWithMaintenanceWindowResponse struct {
	*RegisterTargetWithMaintenanceWindowOutput

	response *aws.Response
}

// SDKResponseMetdata returns the response metadata for the
// RegisterTargetWithMaintenanceWindow request.
func (r *RegisterTargetWithMaintenanceWindowResponse) SDKResponseMetdata() *aws.Response {
	return r.response
}
