// Code generated by go-swagger; DO NOT EDIT.

package models

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
)

// HashicorpCloudIamExchangeWorkloadIdentityTokenRequestToken Token represents an external identity token.
//
// swagger:model hashicorp.cloud.iam.ExchangeWorkloadIdentityTokenRequest.Token
type HashicorpCloudIamExchangeWorkloadIdentityTokenRequestToken struct {

	// AWS4Request is a signed AWS4 [0] request to the GetCallerIdentity
	// endpoint [1]
	//
	// [0] https://docs.aws.amazon.com/IAM/latest/UserGuide/signing-elements.html
	// [1] https://docs.aws.amazon.com/STS/latest/APIReference/API_GetCallerIdentity.html
	AwsGetCallerIDToken *HashicorpCloudIamExchangeWorkloadIdentityTokenRequestTokenAWS4Request `json:"aws_get_caller_id_token,omitempty"`

	// jwt_token is a JWT token.
	JwtToken string `json:"jwt_token,omitempty"`
}

// Validate validates this hashicorp cloud iam exchange workload identity token request token
func (m *HashicorpCloudIamExchangeWorkloadIdentityTokenRequestToken) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateAwsGetCallerIDToken(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *HashicorpCloudIamExchangeWorkloadIdentityTokenRequestToken) validateAwsGetCallerIDToken(formats strfmt.Registry) error {
	if swag.IsZero(m.AwsGetCallerIDToken) { // not required
		return nil
	}

	if m.AwsGetCallerIDToken != nil {
		if err := m.AwsGetCallerIDToken.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("aws_get_caller_id_token")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("aws_get_caller_id_token")
			}
			return err
		}
	}

	return nil
}

// ContextValidate validate this hashicorp cloud iam exchange workload identity token request token based on the context it is used
func (m *HashicorpCloudIamExchangeWorkloadIdentityTokenRequestToken) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	if err := m.contextValidateAwsGetCallerIDToken(ctx, formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *HashicorpCloudIamExchangeWorkloadIdentityTokenRequestToken) contextValidateAwsGetCallerIDToken(ctx context.Context, formats strfmt.Registry) error {

	if m.AwsGetCallerIDToken != nil {

		if swag.IsZero(m.AwsGetCallerIDToken) { // not required
			return nil
		}

		if err := m.AwsGetCallerIDToken.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("aws_get_caller_id_token")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("aws_get_caller_id_token")
			}
			return err
		}
	}

	return nil
}

// MarshalBinary interface implementation
func (m *HashicorpCloudIamExchangeWorkloadIdentityTokenRequestToken) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

// UnmarshalBinary interface implementation
func (m *HashicorpCloudIamExchangeWorkloadIdentityTokenRequestToken) UnmarshalBinary(b []byte) error {
	var res HashicorpCloudIamExchangeWorkloadIdentityTokenRequestToken
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*m = res
	return nil
}
