// 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"
)

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

const (
	DestinationMysqlUpdateSchemasTunnelMethodTunnelMethodSSHPasswordAuth DestinationMysqlUpdateSchemasTunnelMethodTunnelMethod = "SSH_PASSWORD_AUTH"
)

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

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

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

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

func (o *DestinationMysqlUpdatePasswordAuthentication) GetTunnelMethod() DestinationMysqlUpdateSchemasTunnelMethodTunnelMethod {
	return DestinationMysqlUpdateSchemasTunnelMethodTunnelMethodSSHPasswordAuth
}

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

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

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

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

const (
	DestinationMysqlUpdateSchemasTunnelMethodSSHKeyAuth DestinationMysqlUpdateSchemasTunnelMethod = "SSH_KEY_AUTH"
)

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

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

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

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

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

func (o *DestinationMysqlUpdateSSHKeyAuthentication) GetTunnelMethod() DestinationMysqlUpdateSchemasTunnelMethod {
	return DestinationMysqlUpdateSchemasTunnelMethodSSHKeyAuth
}

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

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

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

const (
	DestinationMysqlUpdateTunnelMethodNoTunnel DestinationMysqlUpdateTunnelMethod = "NO_TUNNEL"
)

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

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

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

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

func (o *DestinationMysqlUpdateNoTunnel) GetTunnelMethod() DestinationMysqlUpdateTunnelMethod {
	return DestinationMysqlUpdateTunnelMethodNoTunnel
}

type DestinationMysqlUpdateSSHTunnelMethodType string

const (
	DestinationMysqlUpdateSSHTunnelMethodTypeDestinationMysqlUpdateNoTunnel               DestinationMysqlUpdateSSHTunnelMethodType = "destination-mysql-update_No Tunnel"
	DestinationMysqlUpdateSSHTunnelMethodTypeDestinationMysqlUpdateSSHKeyAuthentication   DestinationMysqlUpdateSSHTunnelMethodType = "destination-mysql-update_SSH Key Authentication"
	DestinationMysqlUpdateSSHTunnelMethodTypeDestinationMysqlUpdatePasswordAuthentication DestinationMysqlUpdateSSHTunnelMethodType = "destination-mysql-update_Password Authentication"
)

// DestinationMysqlUpdateSSHTunnelMethod - Whether to initiate an SSH tunnel before connecting to the database, and if so, which kind of authentication to use.
type DestinationMysqlUpdateSSHTunnelMethod struct {
	DestinationMysqlUpdateNoTunnel               *DestinationMysqlUpdateNoTunnel               `queryParam:"inline"`
	DestinationMysqlUpdateSSHKeyAuthentication   *DestinationMysqlUpdateSSHKeyAuthentication   `queryParam:"inline"`
	DestinationMysqlUpdatePasswordAuthentication *DestinationMysqlUpdatePasswordAuthentication `queryParam:"inline"`

	Type DestinationMysqlUpdateSSHTunnelMethodType
}

func CreateDestinationMysqlUpdateSSHTunnelMethodDestinationMysqlUpdateNoTunnel(destinationMysqlUpdateNoTunnel DestinationMysqlUpdateNoTunnel) DestinationMysqlUpdateSSHTunnelMethod {
	typ := DestinationMysqlUpdateSSHTunnelMethodTypeDestinationMysqlUpdateNoTunnel

	return DestinationMysqlUpdateSSHTunnelMethod{
		DestinationMysqlUpdateNoTunnel: &destinationMysqlUpdateNoTunnel,
		Type:                           typ,
	}
}

func CreateDestinationMysqlUpdateSSHTunnelMethodDestinationMysqlUpdateSSHKeyAuthentication(destinationMysqlUpdateSSHKeyAuthentication DestinationMysqlUpdateSSHKeyAuthentication) DestinationMysqlUpdateSSHTunnelMethod {
	typ := DestinationMysqlUpdateSSHTunnelMethodTypeDestinationMysqlUpdateSSHKeyAuthentication

	return DestinationMysqlUpdateSSHTunnelMethod{
		DestinationMysqlUpdateSSHKeyAuthentication: &destinationMysqlUpdateSSHKeyAuthentication,
		Type: typ,
	}
}

func CreateDestinationMysqlUpdateSSHTunnelMethodDestinationMysqlUpdatePasswordAuthentication(destinationMysqlUpdatePasswordAuthentication DestinationMysqlUpdatePasswordAuthentication) DestinationMysqlUpdateSSHTunnelMethod {
	typ := DestinationMysqlUpdateSSHTunnelMethodTypeDestinationMysqlUpdatePasswordAuthentication

	return DestinationMysqlUpdateSSHTunnelMethod{
		DestinationMysqlUpdatePasswordAuthentication: &destinationMysqlUpdatePasswordAuthentication,
		Type: typ,
	}
}

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

	var destinationMysqlUpdateNoTunnel DestinationMysqlUpdateNoTunnel = DestinationMysqlUpdateNoTunnel{}
	if err := utils.UnmarshalJSON(data, &destinationMysqlUpdateNoTunnel, "", true, true); err == nil {
		u.DestinationMysqlUpdateNoTunnel = &destinationMysqlUpdateNoTunnel
		u.Type = DestinationMysqlUpdateSSHTunnelMethodTypeDestinationMysqlUpdateNoTunnel
		return nil
	}

	var destinationMysqlUpdateSSHKeyAuthentication DestinationMysqlUpdateSSHKeyAuthentication = DestinationMysqlUpdateSSHKeyAuthentication{}
	if err := utils.UnmarshalJSON(data, &destinationMysqlUpdateSSHKeyAuthentication, "", true, true); err == nil {
		u.DestinationMysqlUpdateSSHKeyAuthentication = &destinationMysqlUpdateSSHKeyAuthentication
		u.Type = DestinationMysqlUpdateSSHTunnelMethodTypeDestinationMysqlUpdateSSHKeyAuthentication
		return nil
	}

	var destinationMysqlUpdatePasswordAuthentication DestinationMysqlUpdatePasswordAuthentication = DestinationMysqlUpdatePasswordAuthentication{}
	if err := utils.UnmarshalJSON(data, &destinationMysqlUpdatePasswordAuthentication, "", true, true); err == nil {
		u.DestinationMysqlUpdatePasswordAuthentication = &destinationMysqlUpdatePasswordAuthentication
		u.Type = DestinationMysqlUpdateSSHTunnelMethodTypeDestinationMysqlUpdatePasswordAuthentication
		return nil
	}

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

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

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

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

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

type DestinationMysqlUpdate struct {
	// Name of the database.
	Database string `json:"database"`
	// Disable Writing Final Tables. WARNING! The data format in _airbyte_data is likely stable but there are no guarantees that other metadata columns will remain the same in future versions
	DisableTypeDedupe *bool `default:"false" json:"disable_type_dedupe"`
	// Hostname of the database.
	Host string `json:"host"`
	// Additional properties to pass to the JDBC URL string when connecting to the database formatted as 'key=value' pairs separated by the symbol '&'. (example: key1=value1&key2=value2&key3=value3).
	JdbcURLParams *string `json:"jdbc_url_params,omitempty"`
	// Password associated with the username.
	Password *string `json:"password,omitempty"`
	// Port of the database.
	Port *int64 `default:"3306" json:"port"`
	// The database to write raw tables into
	RawDataSchema *string `json:"raw_data_schema,omitempty"`
	// Encrypt data using SSL.
	Ssl *bool `default:"true" json:"ssl"`
	// Whether to initiate an SSH tunnel before connecting to the database, and if so, which kind of authentication to use.
	TunnelMethod *DestinationMysqlUpdateSSHTunnelMethod `json:"tunnel_method,omitempty"`
	// Username to use to access the database.
	Username string `json:"username"`
}

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

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

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

func (o *DestinationMysqlUpdate) GetDisableTypeDedupe() *bool {
	if o == nil {
		return nil
	}
	return o.DisableTypeDedupe
}

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

func (o *DestinationMysqlUpdate) GetJdbcURLParams() *string {
	if o == nil {
		return nil
	}
	return o.JdbcURLParams
}

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

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

func (o *DestinationMysqlUpdate) GetRawDataSchema() *string {
	if o == nil {
		return nil
	}
	return o.RawDataSchema
}

func (o *DestinationMysqlUpdate) GetSsl() *bool {
	if o == nil {
		return nil
	}
	return o.Ssl
}

func (o *DestinationMysqlUpdate) GetTunnelMethod() *DestinationMysqlUpdateSSHTunnelMethod {
	if o == nil {
		return nil
	}
	return o.TunnelMethod
}

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