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

const (
	DestinationMongodbAuthorizationLoginPassword DestinationMongodbAuthorization = "login/password"
)

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

// LoginPassword - Login/Password.
type LoginPassword struct {
	authorization DestinationMongodbAuthorization `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 (l LoginPassword) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(l, "", false)
}

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

func (o *LoginPassword) GetAuthorization() DestinationMongodbAuthorization {
	return DestinationMongodbAuthorizationLoginPassword
}

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

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

type Authorization string

const (
	AuthorizationNone Authorization = "none"
)

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

// DestinationMongodbNone - None.
type DestinationMongodbNone struct {
	authorization Authorization `const:"none" json:"authorization"`
}

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

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

func (o *DestinationMongodbNone) GetAuthorization() Authorization {
	return AuthorizationNone
}

type AuthorizationTypeType string

const (
	AuthorizationTypeTypeDestinationMongodbNone AuthorizationTypeType = "destination-mongodb_None"
	AuthorizationTypeTypeLoginPassword          AuthorizationTypeType = "Login/Password"
)

// AuthorizationType - Authorization type.
type AuthorizationType struct {
	DestinationMongodbNone *DestinationMongodbNone `queryParam:"inline"`
	LoginPassword          *LoginPassword          `queryParam:"inline"`

	Type AuthorizationTypeType
}

func CreateAuthorizationTypeDestinationMongodbNone(destinationMongodbNone DestinationMongodbNone) AuthorizationType {
	typ := AuthorizationTypeTypeDestinationMongodbNone

	return AuthorizationType{
		DestinationMongodbNone: &destinationMongodbNone,
		Type:                   typ,
	}
}

func CreateAuthorizationTypeLoginPassword(loginPassword LoginPassword) AuthorizationType {
	typ := AuthorizationTypeTypeLoginPassword

	return AuthorizationType{
		LoginPassword: &loginPassword,
		Type:          typ,
	}
}

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

	var destinationMongodbNone DestinationMongodbNone = DestinationMongodbNone{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbNone, "", true, true); err == nil {
		u.DestinationMongodbNone = &destinationMongodbNone
		u.Type = AuthorizationTypeTypeDestinationMongodbNone
		return nil
	}

	var loginPassword LoginPassword = LoginPassword{}
	if err := utils.UnmarshalJSON(data, &loginPassword, "", true, true); err == nil {
		u.LoginPassword = &loginPassword
		u.Type = AuthorizationTypeTypeLoginPassword
		return nil
	}

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

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

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

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

type DestinationMongodbSchemasInstance string

const (
	DestinationMongodbSchemasInstanceAtlas DestinationMongodbSchemasInstance = "atlas"
)

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

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

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

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

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

func (o *MongoDBAtlas) GetInstance() *DestinationMongodbSchemasInstance {
	if o == nil {
		return nil
	}
	return o.Instance
}

type DestinationMongodbInstance string

const (
	DestinationMongodbInstanceReplica DestinationMongodbInstance = "replica"
)

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

type ReplicaSet struct {
	Instance *DestinationMongodbInstance `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 (r ReplicaSet) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(r, "", false)
}

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

func (o *ReplicaSet) GetInstance() *DestinationMongodbInstance {
	if o == nil {
		return nil
	}
	return o.Instance
}

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

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

type Instance string

const (
	InstanceStandalone Instance = "standalone"
)

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

type StandaloneMongoDbInstance struct {
	// The Host of a Mongo database to be replicated.
	Host     string    `json:"host"`
	Instance *Instance `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 (s StandaloneMongoDbInstance) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(s, "", false)
}

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

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

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

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

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

type MongoDbInstanceTypeType string

const (
	MongoDbInstanceTypeTypeStandaloneMongoDbInstance MongoDbInstanceTypeType = "Standalone MongoDb Instance"
	MongoDbInstanceTypeTypeReplicaSet                MongoDbInstanceTypeType = "Replica Set"
	MongoDbInstanceTypeTypeMongoDBAtlas              MongoDbInstanceTypeType = "MongoDB Atlas"
)

// MongoDbInstanceType - MongoDb instance to connect to. For MongoDB Atlas and Replica Set TLS connection is used by default.
type MongoDbInstanceType struct {
	StandaloneMongoDbInstance *StandaloneMongoDbInstance `queryParam:"inline"`
	ReplicaSet                *ReplicaSet                `queryParam:"inline"`
	MongoDBAtlas              *MongoDBAtlas              `queryParam:"inline"`

	Type MongoDbInstanceTypeType
}

func CreateMongoDbInstanceTypeStandaloneMongoDbInstance(standaloneMongoDbInstance StandaloneMongoDbInstance) MongoDbInstanceType {
	typ := MongoDbInstanceTypeTypeStandaloneMongoDbInstance

	return MongoDbInstanceType{
		StandaloneMongoDbInstance: &standaloneMongoDbInstance,
		Type:                      typ,
	}
}

func CreateMongoDbInstanceTypeReplicaSet(replicaSet ReplicaSet) MongoDbInstanceType {
	typ := MongoDbInstanceTypeTypeReplicaSet

	return MongoDbInstanceType{
		ReplicaSet: &replicaSet,
		Type:       typ,
	}
}

func CreateMongoDbInstanceTypeMongoDBAtlas(mongoDBAtlas MongoDBAtlas) MongoDbInstanceType {
	typ := MongoDbInstanceTypeTypeMongoDBAtlas

	return MongoDbInstanceType{
		MongoDBAtlas: &mongoDBAtlas,
		Type:         typ,
	}
}

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

	var mongoDBAtlas MongoDBAtlas = MongoDBAtlas{}
	if err := utils.UnmarshalJSON(data, &mongoDBAtlas, "", true, true); err == nil {
		u.MongoDBAtlas = &mongoDBAtlas
		u.Type = MongoDbInstanceTypeTypeMongoDBAtlas
		return nil
	}

	var replicaSet ReplicaSet = ReplicaSet{}
	if err := utils.UnmarshalJSON(data, &replicaSet, "", true, true); err == nil {
		u.ReplicaSet = &replicaSet
		u.Type = MongoDbInstanceTypeTypeReplicaSet
		return nil
	}

	var standaloneMongoDbInstance StandaloneMongoDbInstance = StandaloneMongoDbInstance{}
	if err := utils.UnmarshalJSON(data, &standaloneMongoDbInstance, "", true, true); err == nil {
		u.StandaloneMongoDbInstance = &standaloneMongoDbInstance
		u.Type = MongoDbInstanceTypeTypeStandaloneMongoDbInstance
		return nil
	}

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

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

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

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

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

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

const (
	DestinationMongodbSchemasTunnelMethodTunnelMethodSSHPasswordAuth DestinationMongodbSchemasTunnelMethodTunnelMethod = "SSH_PASSWORD_AUTH"
)

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

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

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

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

func (o *DestinationMongodbPasswordAuthentication) GetTunnelMethod() DestinationMongodbSchemasTunnelMethodTunnelMethod {
	return DestinationMongodbSchemasTunnelMethodTunnelMethodSSHPasswordAuth
}

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

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

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

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

const (
	DestinationMongodbSchemasTunnelMethodSSHKeyAuth DestinationMongodbSchemasTunnelMethod = "SSH_KEY_AUTH"
)

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

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

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

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

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

func (o *DestinationMongodbSSHKeyAuthentication) GetTunnelMethod() DestinationMongodbSchemasTunnelMethod {
	return DestinationMongodbSchemasTunnelMethodSSHKeyAuth
}

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

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

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

const (
	DestinationMongodbTunnelMethodNoTunnel DestinationMongodbTunnelMethod = "NO_TUNNEL"
)

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

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

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

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

func (o *DestinationMongodbNoTunnel) GetTunnelMethod() DestinationMongodbTunnelMethod {
	return DestinationMongodbTunnelMethodNoTunnel
}

type DestinationMongodbSSHTunnelMethodType string

const (
	DestinationMongodbSSHTunnelMethodTypeDestinationMongodbNoTunnel               DestinationMongodbSSHTunnelMethodType = "destination-mongodb_No Tunnel"
	DestinationMongodbSSHTunnelMethodTypeDestinationMongodbSSHKeyAuthentication   DestinationMongodbSSHTunnelMethodType = "destination-mongodb_SSH Key Authentication"
	DestinationMongodbSSHTunnelMethodTypeDestinationMongodbPasswordAuthentication DestinationMongodbSSHTunnelMethodType = "destination-mongodb_Password Authentication"
)

// DestinationMongodbSSHTunnelMethod - Whether to initiate an SSH tunnel before connecting to the database, and if so, which kind of authentication to use.
type DestinationMongodbSSHTunnelMethod struct {
	DestinationMongodbNoTunnel               *DestinationMongodbNoTunnel               `queryParam:"inline"`
	DestinationMongodbSSHKeyAuthentication   *DestinationMongodbSSHKeyAuthentication   `queryParam:"inline"`
	DestinationMongodbPasswordAuthentication *DestinationMongodbPasswordAuthentication `queryParam:"inline"`

	Type DestinationMongodbSSHTunnelMethodType
}

func CreateDestinationMongodbSSHTunnelMethodDestinationMongodbNoTunnel(destinationMongodbNoTunnel DestinationMongodbNoTunnel) DestinationMongodbSSHTunnelMethod {
	typ := DestinationMongodbSSHTunnelMethodTypeDestinationMongodbNoTunnel

	return DestinationMongodbSSHTunnelMethod{
		DestinationMongodbNoTunnel: &destinationMongodbNoTunnel,
		Type:                       typ,
	}
}

func CreateDestinationMongodbSSHTunnelMethodDestinationMongodbSSHKeyAuthentication(destinationMongodbSSHKeyAuthentication DestinationMongodbSSHKeyAuthentication) DestinationMongodbSSHTunnelMethod {
	typ := DestinationMongodbSSHTunnelMethodTypeDestinationMongodbSSHKeyAuthentication

	return DestinationMongodbSSHTunnelMethod{
		DestinationMongodbSSHKeyAuthentication: &destinationMongodbSSHKeyAuthentication,
		Type:                                   typ,
	}
}

func CreateDestinationMongodbSSHTunnelMethodDestinationMongodbPasswordAuthentication(destinationMongodbPasswordAuthentication DestinationMongodbPasswordAuthentication) DestinationMongodbSSHTunnelMethod {
	typ := DestinationMongodbSSHTunnelMethodTypeDestinationMongodbPasswordAuthentication

	return DestinationMongodbSSHTunnelMethod{
		DestinationMongodbPasswordAuthentication: &destinationMongodbPasswordAuthentication,
		Type:                                     typ,
	}
}

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

	var destinationMongodbNoTunnel DestinationMongodbNoTunnel = DestinationMongodbNoTunnel{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbNoTunnel, "", true, true); err == nil {
		u.DestinationMongodbNoTunnel = &destinationMongodbNoTunnel
		u.Type = DestinationMongodbSSHTunnelMethodTypeDestinationMongodbNoTunnel
		return nil
	}

	var destinationMongodbSSHKeyAuthentication DestinationMongodbSSHKeyAuthentication = DestinationMongodbSSHKeyAuthentication{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbSSHKeyAuthentication, "", true, true); err == nil {
		u.DestinationMongodbSSHKeyAuthentication = &destinationMongodbSSHKeyAuthentication
		u.Type = DestinationMongodbSSHTunnelMethodTypeDestinationMongodbSSHKeyAuthentication
		return nil
	}

	var destinationMongodbPasswordAuthentication DestinationMongodbPasswordAuthentication = DestinationMongodbPasswordAuthentication{}
	if err := utils.UnmarshalJSON(data, &destinationMongodbPasswordAuthentication, "", true, true); err == nil {
		u.DestinationMongodbPasswordAuthentication = &destinationMongodbPasswordAuthentication
		u.Type = DestinationMongodbSSHTunnelMethodTypeDestinationMongodbPasswordAuthentication
		return nil
	}

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

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

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

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

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

type Mongodb string

const (
	MongodbMongodb Mongodb = "mongodb"
)

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

type DestinationMongodb struct {
	// Authorization type.
	AuthType AuthorizationType `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 *MongoDbInstanceType `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    *DestinationMongodbSSHTunnelMethod `json:"tunnel_method,omitempty"`
	destinationType Mongodb                            `const:"mongodb" json:"destinationType"`
}

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

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

func (o *DestinationMongodb) GetAuthType() AuthorizationType {
	if o == nil {
		return AuthorizationType{}
	}
	return o.AuthType
}

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

func (o *DestinationMongodb) GetInstanceType() *MongoDbInstanceType {
	if o == nil {
		return nil
	}
	return o.InstanceType
}

func (o *DestinationMongodb) GetTunnelMethod() *DestinationMongodbSSHTunnelMethod {
	if o == nil {
		return nil
	}
	return o.TunnelMethod
}

func (o *DestinationMongodb) GetDestinationType() Mongodb {
	return MongodbMongodb
}
