// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.

package shared

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/airbytehq/terraform-provider-airbyte/internal/sdk/internal/utils"
)

type DestinationElasticsearchUpdateSchemasAuthenticationMethodMethod string

const (
	DestinationElasticsearchUpdateSchemasAuthenticationMethodMethodBasic DestinationElasticsearchUpdateSchemasAuthenticationMethodMethod = "basic"
)

func (e DestinationElasticsearchUpdateSchemasAuthenticationMethodMethod) ToPointer() *DestinationElasticsearchUpdateSchemasAuthenticationMethodMethod {
	return &e
}
func (e *DestinationElasticsearchUpdateSchemasAuthenticationMethodMethod) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "basic":
		*e = DestinationElasticsearchUpdateSchemasAuthenticationMethodMethod(v)
		return nil
	default:
		return fmt.Errorf("invalid value for DestinationElasticsearchUpdateSchemasAuthenticationMethodMethod: %v", v)
	}
}

// DestinationElasticsearchUpdateUsernamePassword - Basic auth header with a username and password
type DestinationElasticsearchUpdateUsernamePassword struct {
	method DestinationElasticsearchUpdateSchemasAuthenticationMethodMethod `const:"basic" json:"method"`
	// Basic auth password to access a secure Elasticsearch server
	Password string `json:"password"`
	// Basic auth username to access a secure Elasticsearch server
	Username string `json:"username"`
}

func (d DestinationElasticsearchUpdateUsernamePassword) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(d, "", false)
}

func (d *DestinationElasticsearchUpdateUsernamePassword) UnmarshalJSON(data []byte) error {
	if err := utils.UnmarshalJSON(data, &d, "", false, true); err != nil {
		return err
	}
	return nil
}

func (o *DestinationElasticsearchUpdateUsernamePassword) GetMethod() DestinationElasticsearchUpdateSchemasAuthenticationMethodMethod {
	return DestinationElasticsearchUpdateSchemasAuthenticationMethodMethodBasic
}

func (o *DestinationElasticsearchUpdateUsernamePassword) GetPassword() string {
	if o == nil {
		return ""
	}
	return o.Password
}

func (o *DestinationElasticsearchUpdateUsernamePassword) GetUsername() string {
	if o == nil {
		return ""
	}
	return o.Username
}

type DestinationElasticsearchUpdateSchemasMethod string

const (
	DestinationElasticsearchUpdateSchemasMethodSecret DestinationElasticsearchUpdateSchemasMethod = "secret"
)

func (e DestinationElasticsearchUpdateSchemasMethod) ToPointer() *DestinationElasticsearchUpdateSchemasMethod {
	return &e
}
func (e *DestinationElasticsearchUpdateSchemasMethod) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "secret":
		*e = DestinationElasticsearchUpdateSchemasMethod(v)
		return nil
	default:
		return fmt.Errorf("invalid value for DestinationElasticsearchUpdateSchemasMethod: %v", v)
	}
}

// DestinationElasticsearchUpdateAPIKeySecret - Use a api key and secret combination to authenticate
type DestinationElasticsearchUpdateAPIKeySecret struct {
	// The Key ID to used when accessing an enterprise Elasticsearch instance.
	APIKeyID string `json:"apiKeyId"`
	// The secret associated with the API Key ID.
	APIKeySecret string                                      `json:"apiKeySecret"`
	method       DestinationElasticsearchUpdateSchemasMethod `const:"secret" json:"method"`
}

func (d DestinationElasticsearchUpdateAPIKeySecret) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(d, "", false)
}

func (d *DestinationElasticsearchUpdateAPIKeySecret) UnmarshalJSON(data []byte) error {
	if err := utils.UnmarshalJSON(data, &d, "", false, true); err != nil {
		return err
	}
	return nil
}

func (o *DestinationElasticsearchUpdateAPIKeySecret) GetAPIKeyID() string {
	if o == nil {
		return ""
	}
	return o.APIKeyID
}

func (o *DestinationElasticsearchUpdateAPIKeySecret) GetAPIKeySecret() string {
	if o == nil {
		return ""
	}
	return o.APIKeySecret
}

func (o *DestinationElasticsearchUpdateAPIKeySecret) GetMethod() DestinationElasticsearchUpdateSchemasMethod {
	return DestinationElasticsearchUpdateSchemasMethodSecret
}

type DestinationElasticsearchUpdateMethod string

const (
	DestinationElasticsearchUpdateMethodNone DestinationElasticsearchUpdateMethod = "none"
)

func (e DestinationElasticsearchUpdateMethod) ToPointer() *DestinationElasticsearchUpdateMethod {
	return &e
}
func (e *DestinationElasticsearchUpdateMethod) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "none":
		*e = DestinationElasticsearchUpdateMethod(v)
		return nil
	default:
		return fmt.Errorf("invalid value for DestinationElasticsearchUpdateMethod: %v", v)
	}
}

// DestinationElasticsearchUpdateNone - No authentication will be used
type DestinationElasticsearchUpdateNone struct {
	method DestinationElasticsearchUpdateMethod `const:"none" json:"method"`
}

func (d DestinationElasticsearchUpdateNone) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(d, "", false)
}

func (d *DestinationElasticsearchUpdateNone) UnmarshalJSON(data []byte) error {
	if err := utils.UnmarshalJSON(data, &d, "", false, true); err != nil {
		return err
	}
	return nil
}

func (o *DestinationElasticsearchUpdateNone) GetMethod() DestinationElasticsearchUpdateMethod {
	return DestinationElasticsearchUpdateMethodNone
}

type DestinationElasticsearchUpdateAuthenticationMethodType string

const (
	DestinationElasticsearchUpdateAuthenticationMethodTypeDestinationElasticsearchUpdateNone             DestinationElasticsearchUpdateAuthenticationMethodType = "destination-elasticsearch-update_None"
	DestinationElasticsearchUpdateAuthenticationMethodTypeDestinationElasticsearchUpdateAPIKeySecret     DestinationElasticsearchUpdateAuthenticationMethodType = "destination-elasticsearch-update_Api Key/Secret"
	DestinationElasticsearchUpdateAuthenticationMethodTypeDestinationElasticsearchUpdateUsernamePassword DestinationElasticsearchUpdateAuthenticationMethodType = "destination-elasticsearch-update_Username/Password"
)

// DestinationElasticsearchUpdateAuthenticationMethod - The type of authentication to be used
type DestinationElasticsearchUpdateAuthenticationMethod struct {
	DestinationElasticsearchUpdateNone             *DestinationElasticsearchUpdateNone             `queryParam:"inline"`
	DestinationElasticsearchUpdateAPIKeySecret     *DestinationElasticsearchUpdateAPIKeySecret     `queryParam:"inline"`
	DestinationElasticsearchUpdateUsernamePassword *DestinationElasticsearchUpdateUsernamePassword `queryParam:"inline"`

	Type DestinationElasticsearchUpdateAuthenticationMethodType
}

func CreateDestinationElasticsearchUpdateAuthenticationMethodDestinationElasticsearchUpdateNone(destinationElasticsearchUpdateNone DestinationElasticsearchUpdateNone) DestinationElasticsearchUpdateAuthenticationMethod {
	typ := DestinationElasticsearchUpdateAuthenticationMethodTypeDestinationElasticsearchUpdateNone

	return DestinationElasticsearchUpdateAuthenticationMethod{
		DestinationElasticsearchUpdateNone: &destinationElasticsearchUpdateNone,
		Type:                               typ,
	}
}

func CreateDestinationElasticsearchUpdateAuthenticationMethodDestinationElasticsearchUpdateAPIKeySecret(destinationElasticsearchUpdateAPIKeySecret DestinationElasticsearchUpdateAPIKeySecret) DestinationElasticsearchUpdateAuthenticationMethod {
	typ := DestinationElasticsearchUpdateAuthenticationMethodTypeDestinationElasticsearchUpdateAPIKeySecret

	return DestinationElasticsearchUpdateAuthenticationMethod{
		DestinationElasticsearchUpdateAPIKeySecret: &destinationElasticsearchUpdateAPIKeySecret,
		Type: typ,
	}
}

func CreateDestinationElasticsearchUpdateAuthenticationMethodDestinationElasticsearchUpdateUsernamePassword(destinationElasticsearchUpdateUsernamePassword DestinationElasticsearchUpdateUsernamePassword) DestinationElasticsearchUpdateAuthenticationMethod {
	typ := DestinationElasticsearchUpdateAuthenticationMethodTypeDestinationElasticsearchUpdateUsernamePassword

	return DestinationElasticsearchUpdateAuthenticationMethod{
		DestinationElasticsearchUpdateUsernamePassword: &destinationElasticsearchUpdateUsernamePassword,
		Type: typ,
	}
}

func (u *DestinationElasticsearchUpdateAuthenticationMethod) UnmarshalJSON(data []byte) error {

	var destinationElasticsearchUpdateNone DestinationElasticsearchUpdateNone = DestinationElasticsearchUpdateNone{}
	if err := utils.UnmarshalJSON(data, &destinationElasticsearchUpdateNone, "", true, true); err == nil {
		u.DestinationElasticsearchUpdateNone = &destinationElasticsearchUpdateNone
		u.Type = DestinationElasticsearchUpdateAuthenticationMethodTypeDestinationElasticsearchUpdateNone
		return nil
	}

	var destinationElasticsearchUpdateAPIKeySecret DestinationElasticsearchUpdateAPIKeySecret = DestinationElasticsearchUpdateAPIKeySecret{}
	if err := utils.UnmarshalJSON(data, &destinationElasticsearchUpdateAPIKeySecret, "", true, true); err == nil {
		u.DestinationElasticsearchUpdateAPIKeySecret = &destinationElasticsearchUpdateAPIKeySecret
		u.Type = DestinationElasticsearchUpdateAuthenticationMethodTypeDestinationElasticsearchUpdateAPIKeySecret
		return nil
	}

	var destinationElasticsearchUpdateUsernamePassword DestinationElasticsearchUpdateUsernamePassword = DestinationElasticsearchUpdateUsernamePassword{}
	if err := utils.UnmarshalJSON(data, &destinationElasticsearchUpdateUsernamePassword, "", true, true); err == nil {
		u.DestinationElasticsearchUpdateUsernamePassword = &destinationElasticsearchUpdateUsernamePassword
		u.Type = DestinationElasticsearchUpdateAuthenticationMethodTypeDestinationElasticsearchUpdateUsernamePassword
		return nil
	}

	return fmt.Errorf("could not unmarshal `%s` into any supported union types for DestinationElasticsearchUpdateAuthenticationMethod", string(data))
}

func (u DestinationElasticsearchUpdateAuthenticationMethod) MarshalJSON() ([]byte, error) {
	if u.DestinationElasticsearchUpdateNone != nil {
		return utils.MarshalJSON(u.DestinationElasticsearchUpdateNone, "", true)
	}

	if u.DestinationElasticsearchUpdateAPIKeySecret != nil {
		return utils.MarshalJSON(u.DestinationElasticsearchUpdateAPIKeySecret, "", true)
	}

	if u.DestinationElasticsearchUpdateUsernamePassword != nil {
		return utils.MarshalJSON(u.DestinationElasticsearchUpdateUsernamePassword, "", true)
	}

	return nil, errors.New("could not marshal union type DestinationElasticsearchUpdateAuthenticationMethod: all fields are null")
}

// DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethod - Connect through a jump server tunnel host using username and password authentication
type DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethod string

const (
	DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethodSSHPasswordAuth DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethod = "SSH_PASSWORD_AUTH"
)

func (e DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethod) ToPointer() *DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethod {
	return &e
}
func (e *DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethod) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "SSH_PASSWORD_AUTH":
		*e = DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethod(v)
		return nil
	default:
		return fmt.Errorf("invalid value for DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethod: %v", v)
	}
}

type DestinationElasticsearchUpdatePasswordAuthentication struct {
	// Hostname of the jump server host that allows inbound ssh tunnel.
	TunnelHost string `json:"tunnel_host"`
	// Connect through a jump server tunnel host using username and password authentication
	tunnelMethod DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethod `const:"SSH_PASSWORD_AUTH" json:"tunnel_method"`
	// Port on the proxy/jump server that accepts inbound ssh connections.
	TunnelPort *int64 `default:"22" json:"tunnel_port"`
	// OS-level username for logging into the jump server host
	TunnelUser string `json:"tunnel_user"`
	// OS-level password for logging into the jump server host
	TunnelUserPassword string `json:"tunnel_user_password"`
}

func (d DestinationElasticsearchUpdatePasswordAuthentication) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(d, "", false)
}

func (d *DestinationElasticsearchUpdatePasswordAuthentication) UnmarshalJSON(data []byte) error {
	if err := utils.UnmarshalJSON(data, &d, "", false, true); err != nil {
		return err
	}
	return nil
}

func (o *DestinationElasticsearchUpdatePasswordAuthentication) GetTunnelHost() string {
	if o == nil {
		return ""
	}
	return o.TunnelHost
}

func (o *DestinationElasticsearchUpdatePasswordAuthentication) GetTunnelMethod() DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethod {
	return DestinationElasticsearchUpdateSchemasTunnelMethodTunnelMethodSSHPasswordAuth
}

func (o *DestinationElasticsearchUpdatePasswordAuthentication) GetTunnelPort() *int64 {
	if o == nil {
		return nil
	}
	return o.TunnelPort
}

func (o *DestinationElasticsearchUpdatePasswordAuthentication) GetTunnelUser() string {
	if o == nil {
		return ""
	}
	return o.TunnelUser
}

func (o *DestinationElasticsearchUpdatePasswordAuthentication) GetTunnelUserPassword() string {
	if o == nil {
		return ""
	}
	return o.TunnelUserPassword
}

// DestinationElasticsearchUpdateSchemasTunnelMethod - Connect through a jump server tunnel host using username and ssh key
type DestinationElasticsearchUpdateSchemasTunnelMethod string

const (
	DestinationElasticsearchUpdateSchemasTunnelMethodSSHKeyAuth DestinationElasticsearchUpdateSchemasTunnelMethod = "SSH_KEY_AUTH"
)

func (e DestinationElasticsearchUpdateSchemasTunnelMethod) ToPointer() *DestinationElasticsearchUpdateSchemasTunnelMethod {
	return &e
}
func (e *DestinationElasticsearchUpdateSchemasTunnelMethod) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "SSH_KEY_AUTH":
		*e = DestinationElasticsearchUpdateSchemasTunnelMethod(v)
		return nil
	default:
		return fmt.Errorf("invalid value for DestinationElasticsearchUpdateSchemasTunnelMethod: %v", v)
	}
}

type DestinationElasticsearchUpdateSSHKeyAuthentication struct {
	// OS-level user account ssh key credentials in RSA PEM format ( created with ssh-keygen -t rsa -m PEM -f myuser_rsa )
	SSHKey string `json:"ssh_key"`
	// Hostname of the jump server host that allows inbound ssh tunnel.
	TunnelHost string `json:"tunnel_host"`
	// Connect through a jump server tunnel host using username and ssh key
	tunnelMethod DestinationElasticsearchUpdateSchemasTunnelMethod `const:"SSH_KEY_AUTH" json:"tunnel_method"`
	// Port on the proxy/jump server that accepts inbound ssh connections.
	TunnelPort *int64 `default:"22" json:"tunnel_port"`
	// OS-level username for logging into the jump server host.
	TunnelUser string `json:"tunnel_user"`
}

func (d DestinationElasticsearchUpdateSSHKeyAuthentication) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(d, "", false)
}

func (d *DestinationElasticsearchUpdateSSHKeyAuthentication) UnmarshalJSON(data []byte) error {
	if err := utils.UnmarshalJSON(data, &d, "", false, true); err != nil {
		return err
	}
	return nil
}

func (o *DestinationElasticsearchUpdateSSHKeyAuthentication) GetSSHKey() string {
	if o == nil {
		return ""
	}
	return o.SSHKey
}

func (o *DestinationElasticsearchUpdateSSHKeyAuthentication) GetTunnelHost() string {
	if o == nil {
		return ""
	}
	return o.TunnelHost
}

func (o *DestinationElasticsearchUpdateSSHKeyAuthentication) GetTunnelMethod() DestinationElasticsearchUpdateSchemasTunnelMethod {
	return DestinationElasticsearchUpdateSchemasTunnelMethodSSHKeyAuth
}

func (o *DestinationElasticsearchUpdateSSHKeyAuthentication) GetTunnelPort() *int64 {
	if o == nil {
		return nil
	}
	return o.TunnelPort
}

func (o *DestinationElasticsearchUpdateSSHKeyAuthentication) GetTunnelUser() string {
	if o == nil {
		return ""
	}
	return o.TunnelUser
}

// DestinationElasticsearchUpdateTunnelMethod - No ssh tunnel needed to connect to database
type DestinationElasticsearchUpdateTunnelMethod string

const (
	DestinationElasticsearchUpdateTunnelMethodNoTunnel DestinationElasticsearchUpdateTunnelMethod = "NO_TUNNEL"
)

func (e DestinationElasticsearchUpdateTunnelMethod) ToPointer() *DestinationElasticsearchUpdateTunnelMethod {
	return &e
}
func (e *DestinationElasticsearchUpdateTunnelMethod) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "NO_TUNNEL":
		*e = DestinationElasticsearchUpdateTunnelMethod(v)
		return nil
	default:
		return fmt.Errorf("invalid value for DestinationElasticsearchUpdateTunnelMethod: %v", v)
	}
}

type DestinationElasticsearchUpdateNoTunnel struct {
	// No ssh tunnel needed to connect to database
	tunnelMethod DestinationElasticsearchUpdateTunnelMethod `const:"NO_TUNNEL" json:"tunnel_method"`
}

func (d DestinationElasticsearchUpdateNoTunnel) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(d, "", false)
}

func (d *DestinationElasticsearchUpdateNoTunnel) UnmarshalJSON(data []byte) error {
	if err := utils.UnmarshalJSON(data, &d, "", false, true); err != nil {
		return err
	}
	return nil
}

func (o *DestinationElasticsearchUpdateNoTunnel) GetTunnelMethod() DestinationElasticsearchUpdateTunnelMethod {
	return DestinationElasticsearchUpdateTunnelMethodNoTunnel
}

type DestinationElasticsearchUpdateSSHTunnelMethodType string

const (
	DestinationElasticsearchUpdateSSHTunnelMethodTypeDestinationElasticsearchUpdateNoTunnel               DestinationElasticsearchUpdateSSHTunnelMethodType = "destination-elasticsearch-update_No Tunnel"
	DestinationElasticsearchUpdateSSHTunnelMethodTypeDestinationElasticsearchUpdateSSHKeyAuthentication   DestinationElasticsearchUpdateSSHTunnelMethodType = "destination-elasticsearch-update_SSH Key Authentication"
	DestinationElasticsearchUpdateSSHTunnelMethodTypeDestinationElasticsearchUpdatePasswordAuthentication DestinationElasticsearchUpdateSSHTunnelMethodType = "destination-elasticsearch-update_Password Authentication"
)

// DestinationElasticsearchUpdateSSHTunnelMethod - Whether to initiate an SSH tunnel before connecting to the database, and if so, which kind of authentication to use.
type DestinationElasticsearchUpdateSSHTunnelMethod struct {
	DestinationElasticsearchUpdateNoTunnel               *DestinationElasticsearchUpdateNoTunnel               `queryParam:"inline"`
	DestinationElasticsearchUpdateSSHKeyAuthentication   *DestinationElasticsearchUpdateSSHKeyAuthentication   `queryParam:"inline"`
	DestinationElasticsearchUpdatePasswordAuthentication *DestinationElasticsearchUpdatePasswordAuthentication `queryParam:"inline"`

	Type DestinationElasticsearchUpdateSSHTunnelMethodType
}

func CreateDestinationElasticsearchUpdateSSHTunnelMethodDestinationElasticsearchUpdateNoTunnel(destinationElasticsearchUpdateNoTunnel DestinationElasticsearchUpdateNoTunnel) DestinationElasticsearchUpdateSSHTunnelMethod {
	typ := DestinationElasticsearchUpdateSSHTunnelMethodTypeDestinationElasticsearchUpdateNoTunnel

	return DestinationElasticsearchUpdateSSHTunnelMethod{
		DestinationElasticsearchUpdateNoTunnel: &destinationElasticsearchUpdateNoTunnel,
		Type:                                   typ,
	}
}

func CreateDestinationElasticsearchUpdateSSHTunnelMethodDestinationElasticsearchUpdateSSHKeyAuthentication(destinationElasticsearchUpdateSSHKeyAuthentication DestinationElasticsearchUpdateSSHKeyAuthentication) DestinationElasticsearchUpdateSSHTunnelMethod {
	typ := DestinationElasticsearchUpdateSSHTunnelMethodTypeDestinationElasticsearchUpdateSSHKeyAuthentication

	return DestinationElasticsearchUpdateSSHTunnelMethod{
		DestinationElasticsearchUpdateSSHKeyAuthentication: &destinationElasticsearchUpdateSSHKeyAuthentication,
		Type: typ,
	}
}

func CreateDestinationElasticsearchUpdateSSHTunnelMethodDestinationElasticsearchUpdatePasswordAuthentication(destinationElasticsearchUpdatePasswordAuthentication DestinationElasticsearchUpdatePasswordAuthentication) DestinationElasticsearchUpdateSSHTunnelMethod {
	typ := DestinationElasticsearchUpdateSSHTunnelMethodTypeDestinationElasticsearchUpdatePasswordAuthentication

	return DestinationElasticsearchUpdateSSHTunnelMethod{
		DestinationElasticsearchUpdatePasswordAuthentication: &destinationElasticsearchUpdatePasswordAuthentication,
		Type: typ,
	}
}

func (u *DestinationElasticsearchUpdateSSHTunnelMethod) UnmarshalJSON(data []byte) error {

	var destinationElasticsearchUpdateNoTunnel DestinationElasticsearchUpdateNoTunnel = DestinationElasticsearchUpdateNoTunnel{}
	if err := utils.UnmarshalJSON(data, &destinationElasticsearchUpdateNoTunnel, "", true, true); err == nil {
		u.DestinationElasticsearchUpdateNoTunnel = &destinationElasticsearchUpdateNoTunnel
		u.Type = DestinationElasticsearchUpdateSSHTunnelMethodTypeDestinationElasticsearchUpdateNoTunnel
		return nil
	}

	var destinationElasticsearchUpdateSSHKeyAuthentication DestinationElasticsearchUpdateSSHKeyAuthentication = DestinationElasticsearchUpdateSSHKeyAuthentication{}
	if err := utils.UnmarshalJSON(data, &destinationElasticsearchUpdateSSHKeyAuthentication, "", true, true); err == nil {
		u.DestinationElasticsearchUpdateSSHKeyAuthentication = &destinationElasticsearchUpdateSSHKeyAuthentication
		u.Type = DestinationElasticsearchUpdateSSHTunnelMethodTypeDestinationElasticsearchUpdateSSHKeyAuthentication
		return nil
	}

	var destinationElasticsearchUpdatePasswordAuthentication DestinationElasticsearchUpdatePasswordAuthentication = DestinationElasticsearchUpdatePasswordAuthentication{}
	if err := utils.UnmarshalJSON(data, &destinationElasticsearchUpdatePasswordAuthentication, "", true, true); err == nil {
		u.DestinationElasticsearchUpdatePasswordAuthentication = &destinationElasticsearchUpdatePasswordAuthentication
		u.Type = DestinationElasticsearchUpdateSSHTunnelMethodTypeDestinationElasticsearchUpdatePasswordAuthentication
		return nil
	}

	return fmt.Errorf("could not unmarshal `%s` into any supported union types for DestinationElasticsearchUpdateSSHTunnelMethod", string(data))
}

func (u DestinationElasticsearchUpdateSSHTunnelMethod) MarshalJSON() ([]byte, error) {
	if u.DestinationElasticsearchUpdateNoTunnel != nil {
		return utils.MarshalJSON(u.DestinationElasticsearchUpdateNoTunnel, "", true)
	}

	if u.DestinationElasticsearchUpdateSSHKeyAuthentication != nil {
		return utils.MarshalJSON(u.DestinationElasticsearchUpdateSSHKeyAuthentication, "", true)
	}

	if u.DestinationElasticsearchUpdatePasswordAuthentication != nil {
		return utils.MarshalJSON(u.DestinationElasticsearchUpdatePasswordAuthentication, "", true)
	}

	return nil, errors.New("could not marshal union type DestinationElasticsearchUpdateSSHTunnelMethod: all fields are null")
}

type DestinationElasticsearchUpdate struct {
	// The type of authentication to be used
	AuthenticationMethod *DestinationElasticsearchUpdateAuthenticationMethod `json:"authenticationMethod,omitempty"`
	// CA certificate
	CaCertificate *string `json:"ca_certificate,omitempty"`
	// The full url of the Elasticsearch server
	Endpoint string `json:"endpoint"`
	// The Path Prefix of the Elasticsearch server
	PathPrefix *string `json:"pathPrefix,omitempty"`
	// Whether to initiate an SSH tunnel before connecting to the database, and if so, which kind of authentication to use.
	TunnelMethod *DestinationElasticsearchUpdateSSHTunnelMethod `json:"tunnel_method,omitempty"`
	// If a primary key identifier is defined in the source, an upsert will be performed using the primary key value as the elasticsearch doc id. Does not support composite primary keys.
	Upsert *bool `default:"true" json:"upsert"`
}

func (d DestinationElasticsearchUpdate) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(d, "", false)
}

func (d *DestinationElasticsearchUpdate) UnmarshalJSON(data []byte) error {
	if err := utils.UnmarshalJSON(data, &d, "", false, false); err != nil {
		return err
	}
	return nil
}

func (o *DestinationElasticsearchUpdate) GetAuthenticationMethod() *DestinationElasticsearchUpdateAuthenticationMethod {
	if o == nil {
		return nil
	}
	return o.AuthenticationMethod
}

func (o *DestinationElasticsearchUpdate) GetCaCertificate() *string {
	if o == nil {
		return nil
	}
	return o.CaCertificate
}

func (o *DestinationElasticsearchUpdate) GetEndpoint() string {
	if o == nil {
		return ""
	}
	return o.Endpoint
}

func (o *DestinationElasticsearchUpdate) GetPathPrefix() *string {
	if o == nil {
		return nil
	}
	return o.PathPrefix
}

func (o *DestinationElasticsearchUpdate) GetTunnelMethod() *DestinationElasticsearchUpdateSSHTunnelMethod {
	if o == nil {
		return nil
	}
	return o.TunnelMethod
}

func (o *DestinationElasticsearchUpdate) GetUpsert() *bool {
	if o == nil {
		return nil
	}
	return o.Upsert
}
