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

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

const (
	DestinationClickhouseUpdateSchemasTunnelMethodTunnelMethodSSHPasswordAuth DestinationClickhouseUpdateSchemasTunnelMethodTunnelMethod = "SSH_PASSWORD_AUTH"
)

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

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

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

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

func (o *DestinationClickhouseUpdatePasswordAuthentication) GetTunnelMethod() DestinationClickhouseUpdateSchemasTunnelMethodTunnelMethod {
	return DestinationClickhouseUpdateSchemasTunnelMethodTunnelMethodSSHPasswordAuth
}

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

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

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

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

const (
	DestinationClickhouseUpdateSchemasTunnelMethodSSHKeyAuth DestinationClickhouseUpdateSchemasTunnelMethod = "SSH_KEY_AUTH"
)

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

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

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

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

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

func (o *DestinationClickhouseUpdateSSHKeyAuthentication) GetTunnelMethod() DestinationClickhouseUpdateSchemasTunnelMethod {
	return DestinationClickhouseUpdateSchemasTunnelMethodSSHKeyAuth
}

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

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

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

const (
	DestinationClickhouseUpdateTunnelMethodNoTunnel DestinationClickhouseUpdateTunnelMethod = "NO_TUNNEL"
)

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

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

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

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

func (o *DestinationClickhouseUpdateNoTunnel) GetTunnelMethod() DestinationClickhouseUpdateTunnelMethod {
	return DestinationClickhouseUpdateTunnelMethodNoTunnel
}

type DestinationClickhouseUpdateSSHTunnelMethodType string

const (
	DestinationClickhouseUpdateSSHTunnelMethodTypeDestinationClickhouseUpdateNoTunnel               DestinationClickhouseUpdateSSHTunnelMethodType = "destination-clickhouse-update_No Tunnel"
	DestinationClickhouseUpdateSSHTunnelMethodTypeDestinationClickhouseUpdateSSHKeyAuthentication   DestinationClickhouseUpdateSSHTunnelMethodType = "destination-clickhouse-update_SSH Key Authentication"
	DestinationClickhouseUpdateSSHTunnelMethodTypeDestinationClickhouseUpdatePasswordAuthentication DestinationClickhouseUpdateSSHTunnelMethodType = "destination-clickhouse-update_Password Authentication"
)

// DestinationClickhouseUpdateSSHTunnelMethod - Whether to initiate an SSH tunnel before connecting to the database, and if so, which kind of authentication to use.
type DestinationClickhouseUpdateSSHTunnelMethod struct {
	DestinationClickhouseUpdateNoTunnel               *DestinationClickhouseUpdateNoTunnel               `queryParam:"inline"`
	DestinationClickhouseUpdateSSHKeyAuthentication   *DestinationClickhouseUpdateSSHKeyAuthentication   `queryParam:"inline"`
	DestinationClickhouseUpdatePasswordAuthentication *DestinationClickhouseUpdatePasswordAuthentication `queryParam:"inline"`

	Type DestinationClickhouseUpdateSSHTunnelMethodType
}

func CreateDestinationClickhouseUpdateSSHTunnelMethodDestinationClickhouseUpdateNoTunnel(destinationClickhouseUpdateNoTunnel DestinationClickhouseUpdateNoTunnel) DestinationClickhouseUpdateSSHTunnelMethod {
	typ := DestinationClickhouseUpdateSSHTunnelMethodTypeDestinationClickhouseUpdateNoTunnel

	return DestinationClickhouseUpdateSSHTunnelMethod{
		DestinationClickhouseUpdateNoTunnel: &destinationClickhouseUpdateNoTunnel,
		Type:                                typ,
	}
}

func CreateDestinationClickhouseUpdateSSHTunnelMethodDestinationClickhouseUpdateSSHKeyAuthentication(destinationClickhouseUpdateSSHKeyAuthentication DestinationClickhouseUpdateSSHKeyAuthentication) DestinationClickhouseUpdateSSHTunnelMethod {
	typ := DestinationClickhouseUpdateSSHTunnelMethodTypeDestinationClickhouseUpdateSSHKeyAuthentication

	return DestinationClickhouseUpdateSSHTunnelMethod{
		DestinationClickhouseUpdateSSHKeyAuthentication: &destinationClickhouseUpdateSSHKeyAuthentication,
		Type: typ,
	}
}

func CreateDestinationClickhouseUpdateSSHTunnelMethodDestinationClickhouseUpdatePasswordAuthentication(destinationClickhouseUpdatePasswordAuthentication DestinationClickhouseUpdatePasswordAuthentication) DestinationClickhouseUpdateSSHTunnelMethod {
	typ := DestinationClickhouseUpdateSSHTunnelMethodTypeDestinationClickhouseUpdatePasswordAuthentication

	return DestinationClickhouseUpdateSSHTunnelMethod{
		DestinationClickhouseUpdatePasswordAuthentication: &destinationClickhouseUpdatePasswordAuthentication,
		Type: typ,
	}
}

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

	var destinationClickhouseUpdateNoTunnel DestinationClickhouseUpdateNoTunnel = DestinationClickhouseUpdateNoTunnel{}
	if err := utils.UnmarshalJSON(data, &destinationClickhouseUpdateNoTunnel, "", true, true); err == nil {
		u.DestinationClickhouseUpdateNoTunnel = &destinationClickhouseUpdateNoTunnel
		u.Type = DestinationClickhouseUpdateSSHTunnelMethodTypeDestinationClickhouseUpdateNoTunnel
		return nil
	}

	var destinationClickhouseUpdateSSHKeyAuthentication DestinationClickhouseUpdateSSHKeyAuthentication = DestinationClickhouseUpdateSSHKeyAuthentication{}
	if err := utils.UnmarshalJSON(data, &destinationClickhouseUpdateSSHKeyAuthentication, "", true, true); err == nil {
		u.DestinationClickhouseUpdateSSHKeyAuthentication = &destinationClickhouseUpdateSSHKeyAuthentication
		u.Type = DestinationClickhouseUpdateSSHTunnelMethodTypeDestinationClickhouseUpdateSSHKeyAuthentication
		return nil
	}

	var destinationClickhouseUpdatePasswordAuthentication DestinationClickhouseUpdatePasswordAuthentication = DestinationClickhouseUpdatePasswordAuthentication{}
	if err := utils.UnmarshalJSON(data, &destinationClickhouseUpdatePasswordAuthentication, "", true, true); err == nil {
		u.DestinationClickhouseUpdatePasswordAuthentication = &destinationClickhouseUpdatePasswordAuthentication
		u.Type = DestinationClickhouseUpdateSSHTunnelMethodTypeDestinationClickhouseUpdatePasswordAuthentication
		return nil
	}

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

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

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

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

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

type DestinationClickhouseUpdate struct {
	// Name of the database.
	Database string `json:"database"`
	// 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"`
	// HTTP port of the database.
	Port *int64 `default:"8123" json:"port"`
	// The schema to write raw tables into (default: airbyte_internal)
	RawDataSchema *string `json:"raw_data_schema,omitempty"`
	// Encrypt data using SSL.
	Ssl *bool `default:"false" json:"ssl"`
	// Whether to initiate an SSH tunnel before connecting to the database, and if so, which kind of authentication to use.
	TunnelMethod *DestinationClickhouseUpdateSSHTunnelMethod `json:"tunnel_method,omitempty"`
	// Username to use to access the database.
	Username string `json:"username"`
}

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

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

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

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

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

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

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

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

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

func (o *DestinationClickhouseUpdate) GetTunnelMethod() *DestinationClickhouseUpdateSSHTunnelMethod {
	if o == nil {
		return nil
	}
	return o.TunnelMethod
}

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