// Package messaging provides primitives to interact the openapi HTTP API.
//
// Code generated by go-sdk-codegen DO NOT EDIT.
package messaging

import (
	"encoding/json"
	"fmt"
	"time"

	"github.com/pkg/errors"
)

// Attachment defines model for Attachment.
type Attachment struct {

	// The name of the file, including the extension. This is the file name that will appear in the message. This does not need to match the file name of the file that you uploaded.
	FileName string `json:"fileName"`

	// The identifier of the upload destination. Get this value by calling the createUploadDestination operation of the Uploads API.
	UploadDestinationId string `json:"uploadDestinationId"`
}

// CreateAmazonMotorsRequest defines model for CreateAmazonMotorsRequest.
type CreateAmazonMotorsRequest struct {

	// Attachments to include in the message to the buyer. If any text is included in the attachment, the text must be written in the buyer's language of preference, which can be retrieved from the GetAttributes operation.
	Attachments *[]Attachment `json:"attachments,omitempty"`
}

// CreateAmazonMotorsResponse defines model for CreateAmazonMotorsResponse.
type CreateAmazonMotorsResponse struct {

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// CreateConfirmCustomizationDetailsRequest defines model for CreateConfirmCustomizationDetailsRequest.
type CreateConfirmCustomizationDetailsRequest struct {

	// Attachments to include in the message to the buyer.
	Attachments *[]Attachment `json:"attachments,omitempty"`

	// The text to be sent to the buyer. Only links related to customization details are allowed. Do not include HTML or email addresses. The text must be written in the buyer's language of preference, which can be retrieved from the GetAttributes operation.
	Text *string `json:"text,omitempty"`
}

// CreateConfirmCustomizationDetailsResponse defines model for CreateConfirmCustomizationDetailsResponse.
type CreateConfirmCustomizationDetailsResponse struct {

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// CreateConfirmDeliveryDetailsRequest defines model for CreateConfirmDeliveryDetailsRequest.
type CreateConfirmDeliveryDetailsRequest struct {

	// The text to be sent to the buyer. Only links related to order delivery are allowed. Do not include HTML or email addresses. The text must be written in the buyer's language of preference, which can be retrieved from the GetAttributes operation.
	Text *string `json:"text,omitempty"`
}

// CreateConfirmDeliveryDetailsResponse defines model for CreateConfirmDeliveryDetailsResponse.
type CreateConfirmDeliveryDetailsResponse struct {

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// CreateConfirmOrderDetailsRequest defines model for CreateConfirmOrderDetailsRequest.
type CreateConfirmOrderDetailsRequest struct {

	// The text to be sent to the buyer. Only links related to order completion are allowed. Do not include HTML or email addresses. The text must be written in the buyer's language of preference, which can be retrieved from the GetAttributes operation.
	Text *string `json:"text,omitempty"`
}

// CreateConfirmOrderDetailsResponse defines model for CreateConfirmOrderDetailsResponse.
type CreateConfirmOrderDetailsResponse struct {

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// CreateConfirmServiceDetailsRequest defines model for CreateConfirmServiceDetailsRequest.
type CreateConfirmServiceDetailsRequest struct {

	// The text to be sent to the buyer. Only links related to Home Service calls are allowed. Do not include HTML or email addresses. The text must be written in the buyer's language of preference, which can be retrieved from the GetAttributes operation.
	Text *string `json:"text,omitempty"`
}

// CreateConfirmServiceDetailsResponse defines model for CreateConfirmServiceDetailsResponse.
type CreateConfirmServiceDetailsResponse struct {

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// CreateDigitalAccessKeyRequest defines model for CreateDigitalAccessKeyRequest.
type CreateDigitalAccessKeyRequest struct {

	// Attachments to include in the message to the buyer.
	Attachments *[]Attachment `json:"attachments,omitempty"`

	// The text to be sent to the buyer. Only links related to the digital access key are allowed. Do not include HTML or email addresses. The text must be written in the buyer's language of preference, which can be retrieved from the GetAttributes operation.
	Text *string `json:"text,omitempty"`
}

// CreateDigitalAccessKeyResponse defines model for CreateDigitalAccessKeyResponse.
type CreateDigitalAccessKeyResponse struct {

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// CreateLegalDisclosureRequest defines model for CreateLegalDisclosureRequest.
type CreateLegalDisclosureRequest struct {

	// Attachments to include in the message to the buyer. If any text is included in the attachment, the text must be written in the buyer's language of preference, which can be retrieved from the GetAttributes operation.
	Attachments *[]Attachment `json:"attachments,omitempty"`
}

// CreateLegalDisclosureResponse defines model for CreateLegalDisclosureResponse.
type CreateLegalDisclosureResponse struct {

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// CreateNegativeFeedbackRemovalResponse defines model for CreateNegativeFeedbackRemovalResponse.
type CreateNegativeFeedbackRemovalResponse struct {

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// CreateUnexpectedProblemRequest defines model for CreateUnexpectedProblemRequest.
type CreateUnexpectedProblemRequest struct {

	// The text to be sent to the buyer. Only links related to unexpected problem calls are allowed. Do not include HTML or email addresses. The text must be written in the buyer's language of preference, which can be retrieved from the GetAttributes operation.
	Text *string `json:"text,omitempty"`
}

// CreateUnexpectedProblemResponse defines model for CreateUnexpectedProblemResponse.
type CreateUnexpectedProblemResponse struct {

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// CreateWarrantyRequest defines model for CreateWarrantyRequest.
type CreateWarrantyRequest struct {

	// Attachments to include in the message to the buyer. If any text is included in the attachment, the text must be written in the buyer's language of preference, which can be retrieved from the GetAttributes operation.
	Attachments *[]Attachment `json:"attachments,omitempty"`

	// The end date of the warranty coverage to include in the message to the buyer.
	CoverageEndDate *time.Time `json:"coverageEndDate,omitempty"`

	// The start date of the warranty coverage to include in the message to the buyer.
	CoverageStartDate *time.Time `json:"coverageStartDate,omitempty"`
}

// CreateWarrantyResponse defines model for CreateWarrantyResponse.
type CreateWarrantyResponse struct {

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// Error defines model for Error.
type Error struct {

	// An error code that identifies the type of error that occurred.
	Code string `json:"code"`

	// Additional details that can help the caller understand or fix the issue.
	Details *string `json:"details,omitempty"`

	// A message that describes the error condition.
	Message string `json:"message"`
}

// ErrorList defines model for ErrorList.
type ErrorList []Error

// GetAttributesResponse defines model for GetAttributesResponse.
type GetAttributesResponse struct {

	// The list of attributes related to the buyer.
	Buyer *struct {

		// The buyer's language of preference, indicated with a locale-specific language tag. Examples: "en-US", "zh-CN", and "en-GB".
		Locale *string `json:"locale,omitempty"`
	} `json:"buyer,omitempty"`

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// GetMessagingActionResponse defines model for GetMessagingActionResponse.
type GetMessagingActionResponse struct {
	Embedded *struct {
		Schema *GetSchemaResponse `json:"schema,omitempty"`
	} `json:"_embedded,omitempty"`
	Links *struct {

		// A Link object.
		Schema LinkObject `json:"schema"`

		// A Link object.
		Self LinkObject `json:"self"`
	} `json:"_links,omitempty"`

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`

	// A simple object containing the name of the template.
	Payload *MessagingAction `json:"payload,omitempty"`
}

// GetMessagingActionsForOrderResponse defines model for GetMessagingActionsForOrderResponse.
type GetMessagingActionsForOrderResponse struct {
	Embedded *struct {
		Actions []GetMessagingActionResponse `json:"actions"`
	} `json:"_embedded,omitempty"`
	Links *struct {

		// Eligible actions for the specified amazonOrderId.
		Actions []LinkObject `json:"actions"`

		// A Link object.
		Self LinkObject `json:"self"`
	} `json:"_links,omitempty"`

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`
}

// GetSchemaResponse defines model for GetSchemaResponse.
type GetSchemaResponse struct {
	Links *struct {

		// A Link object.
		Self LinkObject `json:"self"`
	} `json:"_links,omitempty"`

	// A list of error responses returned when a request is unsuccessful.
	Errors *ErrorList `json:"errors,omitempty"`

	// A JSON schema document describing the expected payload of the action. This object can be validated against <a href=http://json-schema.org/draft-04/schema>http://json-schema.org/draft-04/schema</a>.
	Payload *Schema `json:"payload,omitempty"`
}

// LinkObject defines model for LinkObject.
type LinkObject struct {

	// A URI for this object.
	Href string `json:"href"`

	// An identifier for this object.
	Name *string `json:"name,omitempty"`
}

// MessagingAction defines model for MessagingAction.
type MessagingAction struct {
	Name string `json:"name"`
}

// Schema defines model for Schema.
type Schema struct {
	AdditionalProperties map[string]interface{} `json:"-"`
}

// GetMessagingActionsForOrderParams defines parameters for GetMessagingActionsForOrder.
type GetMessagingActionsForOrderParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// GetAttributesParams defines parameters for GetAttributes.
type GetAttributesParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// CreateAmazonMotorsJSONBody defines parameters for CreateAmazonMotors.
type CreateAmazonMotorsJSONBody CreateAmazonMotorsRequest

// CreateAmazonMotorsParams defines parameters for CreateAmazonMotors.
type CreateAmazonMotorsParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// ConfirmCustomizationDetailsJSONBody defines parameters for ConfirmCustomizationDetails.
type ConfirmCustomizationDetailsJSONBody CreateConfirmCustomizationDetailsRequest

// ConfirmCustomizationDetailsParams defines parameters for ConfirmCustomizationDetails.
type ConfirmCustomizationDetailsParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// CreateConfirmDeliveryDetailsJSONBody defines parameters for CreateConfirmDeliveryDetails.
type CreateConfirmDeliveryDetailsJSONBody CreateConfirmDeliveryDetailsRequest

// CreateConfirmDeliveryDetailsParams defines parameters for CreateConfirmDeliveryDetails.
type CreateConfirmDeliveryDetailsParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// CreateConfirmOrderDetailsJSONBody defines parameters for CreateConfirmOrderDetails.
type CreateConfirmOrderDetailsJSONBody CreateConfirmOrderDetailsRequest

// CreateConfirmOrderDetailsParams defines parameters for CreateConfirmOrderDetails.
type CreateConfirmOrderDetailsParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// CreateConfirmServiceDetailsJSONBody defines parameters for CreateConfirmServiceDetails.
type CreateConfirmServiceDetailsJSONBody CreateConfirmServiceDetailsRequest

// CreateConfirmServiceDetailsParams defines parameters for CreateConfirmServiceDetails.
type CreateConfirmServiceDetailsParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// CreateDigitalAccessKeyJSONBody defines parameters for CreateDigitalAccessKey.
type CreateDigitalAccessKeyJSONBody CreateDigitalAccessKeyRequest

// CreateDigitalAccessKeyParams defines parameters for CreateDigitalAccessKey.
type CreateDigitalAccessKeyParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// CreateLegalDisclosureJSONBody defines parameters for CreateLegalDisclosure.
type CreateLegalDisclosureJSONBody CreateLegalDisclosureRequest

// CreateLegalDisclosureParams defines parameters for CreateLegalDisclosure.
type CreateLegalDisclosureParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// CreateNegativeFeedbackRemovalParams defines parameters for CreateNegativeFeedbackRemoval.
type CreateNegativeFeedbackRemovalParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// CreateUnexpectedProblemJSONBody defines parameters for CreateUnexpectedProblem.
type CreateUnexpectedProblemJSONBody CreateUnexpectedProblemRequest

// CreateUnexpectedProblemParams defines parameters for CreateUnexpectedProblem.
type CreateUnexpectedProblemParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// CreateWarrantyJSONBody defines parameters for CreateWarranty.
type CreateWarrantyJSONBody CreateWarrantyRequest

// CreateWarrantyParams defines parameters for CreateWarranty.
type CreateWarrantyParams struct {

	// A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
	MarketplaceIds []string `json:"marketplaceIds"`
}

// CreateAmazonMotorsRequestBody defines body for CreateAmazonMotors for application/json ContentType.
type CreateAmazonMotorsJSONRequestBody CreateAmazonMotorsJSONBody

// ConfirmCustomizationDetailsRequestBody defines body for ConfirmCustomizationDetails for application/json ContentType.
type ConfirmCustomizationDetailsJSONRequestBody ConfirmCustomizationDetailsJSONBody

// CreateConfirmDeliveryDetailsRequestBody defines body for CreateConfirmDeliveryDetails for application/json ContentType.
type CreateConfirmDeliveryDetailsJSONRequestBody CreateConfirmDeliveryDetailsJSONBody

// CreateConfirmOrderDetailsRequestBody defines body for CreateConfirmOrderDetails for application/json ContentType.
type CreateConfirmOrderDetailsJSONRequestBody CreateConfirmOrderDetailsJSONBody

// CreateConfirmServiceDetailsRequestBody defines body for CreateConfirmServiceDetails for application/json ContentType.
type CreateConfirmServiceDetailsJSONRequestBody CreateConfirmServiceDetailsJSONBody

// CreateDigitalAccessKeyRequestBody defines body for CreateDigitalAccessKey for application/json ContentType.
type CreateDigitalAccessKeyJSONRequestBody CreateDigitalAccessKeyJSONBody

// CreateLegalDisclosureRequestBody defines body for CreateLegalDisclosure for application/json ContentType.
type CreateLegalDisclosureJSONRequestBody CreateLegalDisclosureJSONBody

// CreateUnexpectedProblemRequestBody defines body for CreateUnexpectedProblem for application/json ContentType.
type CreateUnexpectedProblemJSONRequestBody CreateUnexpectedProblemJSONBody

// CreateWarrantyRequestBody defines body for CreateWarranty for application/json ContentType.
type CreateWarrantyJSONRequestBody CreateWarrantyJSONBody

// Getter for additional properties for Schema. Returns the specified
// element and whether it was found
func (a Schema) Get(fieldName string) (value interface{}, found bool) {
	if a.AdditionalProperties != nil {
		value, found = a.AdditionalProperties[fieldName]
	}
	return
}

// Setter for additional properties for Schema
func (a *Schema) Set(fieldName string, value interface{}) {
	if a.AdditionalProperties == nil {
		a.AdditionalProperties = make(map[string]interface{})
	}
	a.AdditionalProperties[fieldName] = value
}

// Override default JSON handling for Schema to handle AdditionalProperties
func (a *Schema) UnmarshalJSON(b []byte) error {
	object := make(map[string]json.RawMessage)
	err := json.Unmarshal(b, &object)
	if err != nil {
		return err
	}

	if len(object) != 0 {
		a.AdditionalProperties = make(map[string]interface{})
		for fieldName, fieldBuf := range object {
			var fieldVal interface{}
			err := json.Unmarshal(fieldBuf, &fieldVal)
			if err != nil {
				return errors.Wrap(err, fmt.Sprintf("error unmarshaling field %s", fieldName))
			}
			a.AdditionalProperties[fieldName] = fieldVal
		}
	}
	return nil
}

// Override default JSON handling for Schema to handle AdditionalProperties
func (a Schema) MarshalJSON() ([]byte, error) {
	var err error
	object := make(map[string]json.RawMessage)

	for fieldName, field := range a.AdditionalProperties {
		object[fieldName], err = json.Marshal(field)
		if err != nil {
			return nil, errors.Wrap(err, fmt.Sprintf("error marshaling '%s'", fieldName))
		}
	}
	return json.Marshal(object)
}
