// 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 DestinationMongodbUpdateSchemasAuthorization string

const (
	DestinationMongodbUpdateSchemasAuthorizationLoginPassword DestinationMongodbUpdateSchemasAuthorization = "login/password"
)

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

// DestinationMongodbUpdateLoginPassword - Login/Password.
type DestinationMongodbUpdateLoginPassword struct {
	authorization DestinationMongodbUpdateSchemasAuthorization `const:"login/password" json:"authorization"`
	// Password associated with the username.
	Password string `json:"password"`
	// Username to use to access the database.
	Username string `json:"username"`
}

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

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

func (o *DestinationMongodbUpdateLoginPassword) GetAuthorization() DestinationMongodbUpdateSchemasAuthorization {
	return DestinationMongodbUpdateSchemasAuthorizationLoginPassword
}

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

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

type DestinationMongodbUpdateAuthorization string

const (
	DestinationMongodbUpdateAuthorizationNone DestinationMongodbUpdateAuthorization = "none"
)

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

// DestinationMongodbUpdateNone - None.
type DestinationMongodbUpdateNone struct {
	authorization DestinationMongodbUpdateAuthorization `const:"none" json:"authorization"`
}

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

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

func (o *DestinationMongodbUpdateNone) GetAuthorization() DestinationMongodbUpdateAuthorization {
	return DestinationMongodbUpdateAuthorizationNone
}

type DestinationMongodbUpdateAuthorizationTypeType string

const (
	DestinationMongodbUpdateAuthorizationTypeTypeDestinationMongodbUpdateNone          DestinationMongodbUpdateAuthorizationTypeType = "destination-mongodb-update_None"
	DestinationMongodbUpdateAuthorizationTypeTypeDestinationMongodbUpdateLoginPassword DestinationMongodbUpdateAuthorizationTypeType = "destination-mongodb-update_Login/Password"
)

// DestinationMongodbUpdateAuthorizationType - Authorization type.
type DestinationMongodbUpdateAuthorizationType struct {
	DestinationMongodbUpdateNone          *DestinationMongodbUpdateNone          `queryParam:"inline"`
	DestinationMongodbUpdateLoginPassword *DestinationMongodbUpdateLoginPassword `queryParam:"inline"`

	Type DestinationMongodbUpdateAuthorizationTypeType
}

func CreateDestinationMongodbUpdateAuthorizationTypeDestinationMongodbUpdateNone(destinationMongodbUpdateNone DestinationMongodbUpdateNone) DestinationMongodbUpdateAuthorizationType {
	typ := DestinationMongodbUpdateAuthorizationTypeTypeDestinationMongodbUpdateNone

	return DestinationMongodbUpdateAuthorizationType{
		DestinationMongodbUpdateNone: &destinationMongodbUpdateNone,
		Type:                         typ,
	}
}

func CreateDestinationMongodbUpdateAuthorizationTypeDestinationMongodbUpdateLoginPassword(destinationMongodbUpdateLoginPassword DestinationMongodbUpdateLoginPassword) DestinationMongodbUpdateAuthorizationType {
	typ := DestinationMongodbUpdateAuthorizationTypeTypeDestinationMongodbUpdateLoginPassword

	return DestinationMongodbUpdateAuthorizationType{
		DestinationMongodbUpdateLoginPassword: &destinationMongodbUpdateLoginPassword,
		Type:                                  typ,
	}
}

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

	var destinationMongodbUpdateNone DestinationMongodbUpdateNone = DestinationMongodbUpdateNone{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbUpdateNone, "", true, true); err == nil {
		u.DestinationMongodbUpdateNone = &destinationMongodbUpdateNone
		u.Type = DestinationMongodbUpdateAuthorizationTypeTypeDestinationMongodbUpdateNone
		return nil
	}

	var destinationMongodbUpdateLoginPassword DestinationMongodbUpdateLoginPassword = DestinationMongodbUpdateLoginPassword{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbUpdateLoginPassword, "", true, true); err == nil {
		u.DestinationMongodbUpdateLoginPassword = &destinationMongodbUpdateLoginPassword
		u.Type = DestinationMongodbUpdateAuthorizationTypeTypeDestinationMongodbUpdateLoginPassword
		return nil
	}

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

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

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

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

type DestinationMongodbUpdateSchemasInstanceTypeInstance string

const (
	DestinationMongodbUpdateSchemasInstanceTypeInstanceAtlas DestinationMongodbUpdateSchemasInstanceTypeInstance = "atlas"
)

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

type DestinationMongodbUpdateMongoDBAtlas struct {
	// URL of a cluster to connect to.
	ClusterURL string                                               `json:"cluster_url"`
	Instance   *DestinationMongodbUpdateSchemasInstanceTypeInstance `default:"atlas" json:"instance"`
}

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

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

func (o *DestinationMongodbUpdateMongoDBAtlas) GetClusterURL() string {
	if o == nil {
		return ""
	}
	return o.ClusterURL
}

func (o *DestinationMongodbUpdateMongoDBAtlas) GetInstance() *DestinationMongodbUpdateSchemasInstanceTypeInstance {
	if o == nil {
		return nil
	}
	return o.Instance
}

type DestinationMongodbUpdateSchemasInstance string

const (
	DestinationMongodbUpdateSchemasInstanceReplica DestinationMongodbUpdateSchemasInstance = "replica"
)

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

type DestinationMongodbUpdateReplicaSet struct {
	Instance *DestinationMongodbUpdateSchemasInstance `default:"replica" json:"instance"`
	// A replica set name.
	ReplicaSet *string `json:"replica_set,omitempty"`
	// The members of a replica set. Please specify `host`:`port` of each member seperated by comma.
	ServerAddresses string `json:"server_addresses"`
}

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

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

func (o *DestinationMongodbUpdateReplicaSet) GetInstance() *DestinationMongodbUpdateSchemasInstance {
	if o == nil {
		return nil
	}
	return o.Instance
}

func (o *DestinationMongodbUpdateReplicaSet) GetReplicaSet() *string {
	if o == nil {
		return nil
	}
	return o.ReplicaSet
}

func (o *DestinationMongodbUpdateReplicaSet) GetServerAddresses() string {
	if o == nil {
		return ""
	}
	return o.ServerAddresses
}

type DestinationMongodbUpdateInstance string

const (
	DestinationMongodbUpdateInstanceStandalone DestinationMongodbUpdateInstance = "standalone"
)

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

type DestinationMongodbUpdateStandaloneMongoDbInstance struct {
	// The Host of a Mongo database to be replicated.
	Host     string                            `json:"host"`
	Instance *DestinationMongodbUpdateInstance `default:"standalone" json:"instance"`
	// The Port of a Mongo database to be replicated.
	Port *int64 `default:"27017" json:"port"`
	// Indicates whether TLS encryption protocol will be used to connect to MongoDB. It is recommended to use TLS connection if possible. For more information see <a href="https://docs.airbyte.com/integrations/sources/mongodb-v2">documentation</a>.
	TLS *bool `default:"false" json:"tls"`
}

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

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

func (o *DestinationMongodbUpdateStandaloneMongoDbInstance) GetHost() string {
	if o == nil {
		return ""
	}
	return o.Host
}

func (o *DestinationMongodbUpdateStandaloneMongoDbInstance) GetInstance() *DestinationMongodbUpdateInstance {
	if o == nil {
		return nil
	}
	return o.Instance
}

func (o *DestinationMongodbUpdateStandaloneMongoDbInstance) GetPort() *int64 {
	if o == nil {
		return nil
	}
	return o.Port
}

func (o *DestinationMongodbUpdateStandaloneMongoDbInstance) GetTLS() *bool {
	if o == nil {
		return nil
	}
	return o.TLS
}

type DestinationMongodbUpdateMongoDbInstanceTypeType string

const (
	DestinationMongodbUpdateMongoDbInstanceTypeTypeDestinationMongodbUpdateStandaloneMongoDbInstance DestinationMongodbUpdateMongoDbInstanceTypeType = "destination-mongodb-update_Standalone MongoDb Instance"
	DestinationMongodbUpdateMongoDbInstanceTypeTypeDestinationMongodbUpdateReplicaSet                DestinationMongodbUpdateMongoDbInstanceTypeType = "destination-mongodb-update_Replica Set"
	DestinationMongodbUpdateMongoDbInstanceTypeTypeDestinationMongodbUpdateMongoDBAtlas              DestinationMongodbUpdateMongoDbInstanceTypeType = "destination-mongodb-update_MongoDB Atlas"
)

// DestinationMongodbUpdateMongoDbInstanceType - MongoDb instance to connect to. For MongoDB Atlas and Replica Set TLS connection is used by default.
type DestinationMongodbUpdateMongoDbInstanceType struct {
	DestinationMongodbUpdateStandaloneMongoDbInstance *DestinationMongodbUpdateStandaloneMongoDbInstance `queryParam:"inline"`
	DestinationMongodbUpdateReplicaSet                *DestinationMongodbUpdateReplicaSet                `queryParam:"inline"`
	DestinationMongodbUpdateMongoDBAtlas              *DestinationMongodbUpdateMongoDBAtlas              `queryParam:"inline"`

	Type DestinationMongodbUpdateMongoDbInstanceTypeType
}

func CreateDestinationMongodbUpdateMongoDbInstanceTypeDestinationMongodbUpdateStandaloneMongoDbInstance(destinationMongodbUpdateStandaloneMongoDbInstance DestinationMongodbUpdateStandaloneMongoDbInstance) DestinationMongodbUpdateMongoDbInstanceType {
	typ := DestinationMongodbUpdateMongoDbInstanceTypeTypeDestinationMongodbUpdateStandaloneMongoDbInstance

	return DestinationMongodbUpdateMongoDbInstanceType{
		DestinationMongodbUpdateStandaloneMongoDbInstance: &destinationMongodbUpdateStandaloneMongoDbInstance,
		Type: typ,
	}
}

func CreateDestinationMongodbUpdateMongoDbInstanceTypeDestinationMongodbUpdateReplicaSet(destinationMongodbUpdateReplicaSet DestinationMongodbUpdateReplicaSet) DestinationMongodbUpdateMongoDbInstanceType {
	typ := DestinationMongodbUpdateMongoDbInstanceTypeTypeDestinationMongodbUpdateReplicaSet

	return DestinationMongodbUpdateMongoDbInstanceType{
		DestinationMongodbUpdateReplicaSet: &destinationMongodbUpdateReplicaSet,
		Type:                               typ,
	}
}

func CreateDestinationMongodbUpdateMongoDbInstanceTypeDestinationMongodbUpdateMongoDBAtlas(destinationMongodbUpdateMongoDBAtlas DestinationMongodbUpdateMongoDBAtlas) DestinationMongodbUpdateMongoDbInstanceType {
	typ := DestinationMongodbUpdateMongoDbInstanceTypeTypeDestinationMongodbUpdateMongoDBAtlas

	return DestinationMongodbUpdateMongoDbInstanceType{
		DestinationMongodbUpdateMongoDBAtlas: &destinationMongodbUpdateMongoDBAtlas,
		Type:                                 typ,
	}
}

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

	var destinationMongodbUpdateMongoDBAtlas DestinationMongodbUpdateMongoDBAtlas = DestinationMongodbUpdateMongoDBAtlas{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbUpdateMongoDBAtlas, "", true, true); err == nil {
		u.DestinationMongodbUpdateMongoDBAtlas = &destinationMongodbUpdateMongoDBAtlas
		u.Type = DestinationMongodbUpdateMongoDbInstanceTypeTypeDestinationMongodbUpdateMongoDBAtlas
		return nil
	}

	var destinationMongodbUpdateReplicaSet DestinationMongodbUpdateReplicaSet = DestinationMongodbUpdateReplicaSet{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbUpdateReplicaSet, "", true, true); err == nil {
		u.DestinationMongodbUpdateReplicaSet = &destinationMongodbUpdateReplicaSet
		u.Type = DestinationMongodbUpdateMongoDbInstanceTypeTypeDestinationMongodbUpdateReplicaSet
		return nil
	}

	var destinationMongodbUpdateStandaloneMongoDbInstance DestinationMongodbUpdateStandaloneMongoDbInstance = DestinationMongodbUpdateStandaloneMongoDbInstance{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbUpdateStandaloneMongoDbInstance, "", true, true); err == nil {
		u.DestinationMongodbUpdateStandaloneMongoDbInstance = &destinationMongodbUpdateStandaloneMongoDbInstance
		u.Type = DestinationMongodbUpdateMongoDbInstanceTypeTypeDestinationMongodbUpdateStandaloneMongoDbInstance
		return nil
	}

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

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

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

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

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

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

const (
	DestinationMongodbUpdateSchemasTunnelMethodTunnelMethodSSHPasswordAuth DestinationMongodbUpdateSchemasTunnelMethodTunnelMethod = "SSH_PASSWORD_AUTH"
)

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

type DestinationMongodbUpdatePasswordAuthentication 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 DestinationMongodbUpdateSchemasTunnelMethodTunnelMethod `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 DestinationMongodbUpdatePasswordAuthentication) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(d, "", false)
}

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

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

func (o *DestinationMongodbUpdatePasswordAuthentication) GetTunnelMethod() DestinationMongodbUpdateSchemasTunnelMethodTunnelMethod {
	return DestinationMongodbUpdateSchemasTunnelMethodTunnelMethodSSHPasswordAuth
}

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

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

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

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

const (
	DestinationMongodbUpdateSchemasTunnelMethodSSHKeyAuth DestinationMongodbUpdateSchemasTunnelMethod = "SSH_KEY_AUTH"
)

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

type DestinationMongodbUpdateSSHKeyAuthentication 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 DestinationMongodbUpdateSchemasTunnelMethod `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 DestinationMongodbUpdateSSHKeyAuthentication) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(d, "", false)
}

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

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

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

func (o *DestinationMongodbUpdateSSHKeyAuthentication) GetTunnelMethod() DestinationMongodbUpdateSchemasTunnelMethod {
	return DestinationMongodbUpdateSchemasTunnelMethodSSHKeyAuth
}

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

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

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

const (
	DestinationMongodbUpdateTunnelMethodNoTunnel DestinationMongodbUpdateTunnelMethod = "NO_TUNNEL"
)

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

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

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

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

func (o *DestinationMongodbUpdateNoTunnel) GetTunnelMethod() DestinationMongodbUpdateTunnelMethod {
	return DestinationMongodbUpdateTunnelMethodNoTunnel
}

type DestinationMongodbUpdateSSHTunnelMethodType string

const (
	DestinationMongodbUpdateSSHTunnelMethodTypeDestinationMongodbUpdateNoTunnel               DestinationMongodbUpdateSSHTunnelMethodType = "destination-mongodb-update_No Tunnel"
	DestinationMongodbUpdateSSHTunnelMethodTypeDestinationMongodbUpdateSSHKeyAuthentication   DestinationMongodbUpdateSSHTunnelMethodType = "destination-mongodb-update_SSH Key Authentication"
	DestinationMongodbUpdateSSHTunnelMethodTypeDestinationMongodbUpdatePasswordAuthentication DestinationMongodbUpdateSSHTunnelMethodType = "destination-mongodb-update_Password Authentication"
)

// DestinationMongodbUpdateSSHTunnelMethod - Whether to initiate an SSH tunnel before connecting to the database, and if so, which kind of authentication to use.
type DestinationMongodbUpdateSSHTunnelMethod struct {
	DestinationMongodbUpdateNoTunnel               *DestinationMongodbUpdateNoTunnel               `queryParam:"inline"`
	DestinationMongodbUpdateSSHKeyAuthentication   *DestinationMongodbUpdateSSHKeyAuthentication   `queryParam:"inline"`
	DestinationMongodbUpdatePasswordAuthentication *DestinationMongodbUpdatePasswordAuthentication `queryParam:"inline"`

	Type DestinationMongodbUpdateSSHTunnelMethodType
}

func CreateDestinationMongodbUpdateSSHTunnelMethodDestinationMongodbUpdateNoTunnel(destinationMongodbUpdateNoTunnel DestinationMongodbUpdateNoTunnel) DestinationMongodbUpdateSSHTunnelMethod {
	typ := DestinationMongodbUpdateSSHTunnelMethodTypeDestinationMongodbUpdateNoTunnel

	return DestinationMongodbUpdateSSHTunnelMethod{
		DestinationMongodbUpdateNoTunnel: &destinationMongodbUpdateNoTunnel,
		Type:                             typ,
	}
}

func CreateDestinationMongodbUpdateSSHTunnelMethodDestinationMongodbUpdateSSHKeyAuthentication(destinationMongodbUpdateSSHKeyAuthentication DestinationMongodbUpdateSSHKeyAuthentication) DestinationMongodbUpdateSSHTunnelMethod {
	typ := DestinationMongodbUpdateSSHTunnelMethodTypeDestinationMongodbUpdateSSHKeyAuthentication

	return DestinationMongodbUpdateSSHTunnelMethod{
		DestinationMongodbUpdateSSHKeyAuthentication: &destinationMongodbUpdateSSHKeyAuthentication,
		Type: typ,
	}
}

func CreateDestinationMongodbUpdateSSHTunnelMethodDestinationMongodbUpdatePasswordAuthentication(destinationMongodbUpdatePasswordAuthentication DestinationMongodbUpdatePasswordAuthentication) DestinationMongodbUpdateSSHTunnelMethod {
	typ := DestinationMongodbUpdateSSHTunnelMethodTypeDestinationMongodbUpdatePasswordAuthentication

	return DestinationMongodbUpdateSSHTunnelMethod{
		DestinationMongodbUpdatePasswordAuthentication: &destinationMongodbUpdatePasswordAuthentication,
		Type: typ,
	}
}

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

	var destinationMongodbUpdateNoTunnel DestinationMongodbUpdateNoTunnel = DestinationMongodbUpdateNoTunnel{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbUpdateNoTunnel, "", true, true); err == nil {
		u.DestinationMongodbUpdateNoTunnel = &destinationMongodbUpdateNoTunnel
		u.Type = DestinationMongodbUpdateSSHTunnelMethodTypeDestinationMongodbUpdateNoTunnel
		return nil
	}

	var destinationMongodbUpdateSSHKeyAuthentication DestinationMongodbUpdateSSHKeyAuthentication = DestinationMongodbUpdateSSHKeyAuthentication{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbUpdateSSHKeyAuthentication, "", true, true); err == nil {
		u.DestinationMongodbUpdateSSHKeyAuthentication = &destinationMongodbUpdateSSHKeyAuthentication
		u.Type = DestinationMongodbUpdateSSHTunnelMethodTypeDestinationMongodbUpdateSSHKeyAuthentication
		return nil
	}

	var destinationMongodbUpdatePasswordAuthentication DestinationMongodbUpdatePasswordAuthentication = DestinationMongodbUpdatePasswordAuthentication{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbUpdatePasswordAuthentication, "", true, true); err == nil {
		u.DestinationMongodbUpdatePasswordAuthentication = &destinationMongodbUpdatePasswordAuthentication
		u.Type = DestinationMongodbUpdateSSHTunnelMethodTypeDestinationMongodbUpdatePasswordAuthentication
		return nil
	}

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

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

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

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

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

type DestinationMongodbUpdate struct {
	// Authorization type.
	AuthType DestinationMongodbUpdateAuthorizationType `json:"auth_type"`
	// Name of the database.
	Database string `json:"database"`
	// MongoDb instance to connect to. For MongoDB Atlas and Replica Set TLS connection is used by default.
	InstanceType *DestinationMongodbUpdateMongoDbInstanceType `json:"instance_type,omitempty"`
	// Whether to initiate an SSH tunnel before connecting to the database, and if so, which kind of authentication to use.
	TunnelMethod *DestinationMongodbUpdateSSHTunnelMethod `json:"tunnel_method,omitempty"`
}

func (o *DestinationMongodbUpdate) GetAuthType() DestinationMongodbUpdateAuthorizationType {
	if o == nil {
		return DestinationMongodbUpdateAuthorizationType{}
	}
	return o.AuthType
}

func (o *DestinationMongodbUpdate) GetDatabase() string {
	if o == nil {
		return ""
	}
	return o.Database
}

func (o *DestinationMongodbUpdate) GetInstanceType() *DestinationMongodbUpdateMongoDbInstanceType {
	if o == nil {
		return nil
	}
	return o.InstanceType
}

func (o *DestinationMongodbUpdate) GetTunnelMethod() *DestinationMongodbUpdateSSHTunnelMethod {
	if o == nil {
		return nil
	}
	return o.TunnelMethod
}
