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

package connect

import (
	"context"

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

// Please also see https://docs.aws.amazon.com/goto/WebAPI/connect-2017-08-08/UpdateContactAttributesRequest
type UpdateContactAttributesInput struct {
	_ struct{} `type:"structure"`

	// Specify a custom key-value pair using an attribute map. The attributes are
	// standard Amazon Connect attributes, and can be accessed in contact flows
	// just like any other contact attributes.
	//
	// There can be up to 32,768 UTF-8 bytes across all key-value pairs per contact.
	// Attribute keys can include only alphanumeric, dash, and underscore characters.
	//
	// Attributes is a required field
	Attributes map[string]string `type:"map" required:"true"`

	// The unique identifier of the contact for which to update attributes. This
	// is the identifier for the contact associated with the first interaction with
	// the contact center.
	//
	// InitialContactId is a required field
	InitialContactId *string `min:"1" type:"string" required:"true"`

	// The identifier for your Amazon Connect instance. To find the ID of your instance,
	// open the AWS console and select Amazon Connect. Select the alias of the instance
	// in the Instance alias column. The instance ID is displayed in the Overview
	// section of your instance settings. For example, the instance ID is the set
	// of characters at the end of the instance ARN, after instance/, such as 10a4c4eb-f57e-4d4c-b602-bf39176ced07.
	//
	// InstanceId is a required field
	InstanceId *string `min:"1" type:"string" required:"true"`
}

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

// Validate inspects the fields of the type to determine if they are valid.
func (s *UpdateContactAttributesInput) Validate() error {
	invalidParams := aws.ErrInvalidParams{Context: "UpdateContactAttributesInput"}

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

	if s.InitialContactId == nil {
		invalidParams.Add(aws.NewErrParamRequired("InitialContactId"))
	}
	if s.InitialContactId != nil && len(*s.InitialContactId) < 1 {
		invalidParams.Add(aws.NewErrParamMinLen("InitialContactId", 1))
	}

	if s.InstanceId == nil {
		invalidParams.Add(aws.NewErrParamRequired("InstanceId"))
	}
	if s.InstanceId != nil && len(*s.InstanceId) < 1 {
		invalidParams.Add(aws.NewErrParamMinLen("InstanceId", 1))
	}

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

// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s UpdateContactAttributesInput) MarshalFields(e protocol.FieldEncoder) error {
	e.SetValue(protocol.HeaderTarget, "Content-Type", protocol.StringValue("application/x-amz-json-1.1"), protocol.Metadata{})

	if len(s.Attributes) > 0 {
		v := s.Attributes

		metadata := protocol.Metadata{}
		ms0 := e.Map(protocol.BodyTarget, "Attributes", metadata)
		ms0.Start()
		for k1, v1 := range v {
			ms0.MapSetValue(k1, protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v1)})
		}
		ms0.End()

	}
	if s.InitialContactId != nil {
		v := *s.InitialContactId

		metadata := protocol.Metadata{}
		e.SetValue(protocol.BodyTarget, "InitialContactId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
	}
	if s.InstanceId != nil {
		v := *s.InstanceId

		metadata := protocol.Metadata{}
		e.SetValue(protocol.BodyTarget, "InstanceId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
	}
	return nil
}

// Please also see https://docs.aws.amazon.com/goto/WebAPI/connect-2017-08-08/UpdateContactAttributesResponse
type UpdateContactAttributesOutput struct {
	_ struct{} `type:"structure"`
}

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

// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s UpdateContactAttributesOutput) MarshalFields(e protocol.FieldEncoder) error {
	return nil
}

const opUpdateContactAttributes = "UpdateContactAttributes"

// UpdateContactAttributesRequest returns a request value for making API operation for
// Amazon Connect Service.
//
// The UpdateContactAttributes operation lets you programmatically create new,
// or update existing, contact attributes associated with a contact. You can
// use the operation to add or update attributes for both ongoing and completed
// contacts. For example, you can update the customer's name or the reason the
// customer called while the call is active, or add notes about steps that the
// agent took during the call that are displayed to the next agent that takes
// the call. You can also use the UpdateContactAttributes operation to update
// attributes for a contact using data from your CRM application and save the
// data with the contact in Amazon Connect. You could also flag calls for additional
// analysis, such as legal review or identifying abusive callers.
//
// Contact attributes are available in Amazon Connect for 24 months, and are
// then deleted.
//
// Important:
//
// You cannot use the operation to update attributes for contacts that occurred
// prior to the release of the API, September 12, 2018. You can update attributes
// only for contacts that started after the release of the API. If you attempt
// to update attributes for a contact that occurred prior to the release of
// the API, a 400 error is returned. This applies also to queued callbacks that
// were initiated prior to the release of the API but are still active in your
// instance.
//
//    // Example sending a request using UpdateContactAttributesRequest.
//    req := client.UpdateContactAttributesRequest(params)
//    resp, err := req.Send(context.TODO())
//    if err == nil {
//        fmt.Println(resp)
//    }
//
// Please also see https://docs.aws.amazon.com/goto/WebAPI/connect-2017-08-08/UpdateContactAttributes
func (c *Client) UpdateContactAttributesRequest(input *UpdateContactAttributesInput) UpdateContactAttributesRequest {
	op := &aws.Operation{
		Name:       opUpdateContactAttributes,
		HTTPMethod: "POST",
		HTTPPath:   "/contact/attributes",
	}

	if input == nil {
		input = &UpdateContactAttributesInput{}
	}

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

// UpdateContactAttributesRequest is the request type for the
// UpdateContactAttributes API operation.
type UpdateContactAttributesRequest struct {
	*aws.Request
	Input *UpdateContactAttributesInput
	Copy  func(*UpdateContactAttributesInput) UpdateContactAttributesRequest
}

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

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

	return resp, nil
}

// UpdateContactAttributesResponse is the response type for the
// UpdateContactAttributes API operation.
type UpdateContactAttributesResponse struct {
	*UpdateContactAttributesOutput

	response *aws.Response
}

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