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

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

const (
	SourceClickhouseUpdateSchemasTunnelMethodTunnelMethodSSHPasswordAuth SourceClickhouseUpdateSchemasTunnelMethodTunnelMethod = "SSH_PASSWORD_AUTH"
)

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

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

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

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

func (o *SourceClickhouseUpdatePasswordAuthentication) GetTunnelMethod() SourceClickhouseUpdateSchemasTunnelMethodTunnelMethod {
	return SourceClickhouseUpdateSchemasTunnelMethodTunnelMethodSSHPasswordAuth
}

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

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

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

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

const (
	SourceClickhouseUpdateSchemasTunnelMethodSSHKeyAuth SourceClickhouseUpdateSchemasTunnelMethod = "SSH_KEY_AUTH"
)

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

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

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

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

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

func (o *SourceClickhouseUpdateSSHKeyAuthentication) GetTunnelMethod() SourceClickhouseUpdateSchemasTunnelMethod {
	return SourceClickhouseUpdateSchemasTunnelMethodSSHKeyAuth
}

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

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

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

const (
	SourceClickhouseUpdateTunnelMethodNoTunnel SourceClickhouseUpdateTunnelMethod = "NO_TUNNEL"
)

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

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

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

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

func (o *SourceClickhouseUpdateNoTunnel) GetTunnelMethod() SourceClickhouseUpdateTunnelMethod {
	return SourceClickhouseUpdateTunnelMethodNoTunnel
}

type SourceClickhouseUpdateSSHTunnelMethodType string

const (
	SourceClickhouseUpdateSSHTunnelMethodTypeSourceClickhouseUpdateNoTunnel               SourceClickhouseUpdateSSHTunnelMethodType = "source-clickhouse-update_No Tunnel"
	SourceClickhouseUpdateSSHTunnelMethodTypeSourceClickhouseUpdateSSHKeyAuthentication   SourceClickhouseUpdateSSHTunnelMethodType = "source-clickhouse-update_SSH Key Authentication"
	SourceClickhouseUpdateSSHTunnelMethodTypeSourceClickhouseUpdatePasswordAuthentication SourceClickhouseUpdateSSHTunnelMethodType = "source-clickhouse-update_Password Authentication"
)

// SourceClickhouseUpdateSSHTunnelMethod - Whether to initiate an SSH tunnel before connecting to the database, and if so, which kind of authentication to use.
type SourceClickhouseUpdateSSHTunnelMethod struct {
	SourceClickhouseUpdateNoTunnel               *SourceClickhouseUpdateNoTunnel               `queryParam:"inline"`
	SourceClickhouseUpdateSSHKeyAuthentication   *SourceClickhouseUpdateSSHKeyAuthentication   `queryParam:"inline"`
	SourceClickhouseUpdatePasswordAuthentication *SourceClickhouseUpdatePasswordAuthentication `queryParam:"inline"`

	Type SourceClickhouseUpdateSSHTunnelMethodType
}

func CreateSourceClickhouseUpdateSSHTunnelMethodSourceClickhouseUpdateNoTunnel(sourceClickhouseUpdateNoTunnel SourceClickhouseUpdateNoTunnel) SourceClickhouseUpdateSSHTunnelMethod {
	typ := SourceClickhouseUpdateSSHTunnelMethodTypeSourceClickhouseUpdateNoTunnel

	return SourceClickhouseUpdateSSHTunnelMethod{
		SourceClickhouseUpdateNoTunnel: &sourceClickhouseUpdateNoTunnel,
		Type:                           typ,
	}
}

func CreateSourceClickhouseUpdateSSHTunnelMethodSourceClickhouseUpdateSSHKeyAuthentication(sourceClickhouseUpdateSSHKeyAuthentication SourceClickhouseUpdateSSHKeyAuthentication) SourceClickhouseUpdateSSHTunnelMethod {
	typ := SourceClickhouseUpdateSSHTunnelMethodTypeSourceClickhouseUpdateSSHKeyAuthentication

	return SourceClickhouseUpdateSSHTunnelMethod{
		SourceClickhouseUpdateSSHKeyAuthentication: &sourceClickhouseUpdateSSHKeyAuthentication,
		Type: typ,
	}
}

func CreateSourceClickhouseUpdateSSHTunnelMethodSourceClickhouseUpdatePasswordAuthentication(sourceClickhouseUpdatePasswordAuthentication SourceClickhouseUpdatePasswordAuthentication) SourceClickhouseUpdateSSHTunnelMethod {
	typ := SourceClickhouseUpdateSSHTunnelMethodTypeSourceClickhouseUpdatePasswordAuthentication

	return SourceClickhouseUpdateSSHTunnelMethod{
		SourceClickhouseUpdatePasswordAuthentication: &sourceClickhouseUpdatePasswordAuthentication,
		Type: typ,
	}
}

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

	var sourceClickhouseUpdateNoTunnel SourceClickhouseUpdateNoTunnel = SourceClickhouseUpdateNoTunnel{}
	if err := utils.UnmarshalJSON(data, &sourceClickhouseUpdateNoTunnel, "", true, true); err == nil {
		u.SourceClickhouseUpdateNoTunnel = &sourceClickhouseUpdateNoTunnel
		u.Type = SourceClickhouseUpdateSSHTunnelMethodTypeSourceClickhouseUpdateNoTunnel
		return nil
	}

	var sourceClickhouseUpdateSSHKeyAuthentication SourceClickhouseUpdateSSHKeyAuthentication = SourceClickhouseUpdateSSHKeyAuthentication{}
	if err := utils.UnmarshalJSON(data, &sourceClickhouseUpdateSSHKeyAuthentication, "", true, true); err == nil {
		u.SourceClickhouseUpdateSSHKeyAuthentication = &sourceClickhouseUpdateSSHKeyAuthentication
		u.Type = SourceClickhouseUpdateSSHTunnelMethodTypeSourceClickhouseUpdateSSHKeyAuthentication
		return nil
	}

	var sourceClickhouseUpdatePasswordAuthentication SourceClickhouseUpdatePasswordAuthentication = SourceClickhouseUpdatePasswordAuthentication{}
	if err := utils.UnmarshalJSON(data, &sourceClickhouseUpdatePasswordAuthentication, "", true, true); err == nil {
		u.SourceClickhouseUpdatePasswordAuthentication = &sourceClickhouseUpdatePasswordAuthentication
		u.Type = SourceClickhouseUpdateSSHTunnelMethodTypeSourceClickhouseUpdatePasswordAuthentication
		return nil
	}

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

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

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

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

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

type SourceClickhouseUpdate struct {
	// The name of the database.
	Database string `json:"database"`
	// The host endpoint of the Clickhouse cluster.
	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 '&'. (Eg. key1=value1&key2=value2&key3=value3). For more information read about <a href="https://jdbc.postgresql.org/documentation/head/connect.html">JDBC URL parameters</a>.
	JdbcURLParams *string `json:"jdbc_url_params,omitempty"`
	// The password associated with this username.
	Password *string `json:"password,omitempty"`
	// The port of the database.
	Port *int64 `default:"8123" json:"port"`
	// 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 *SourceClickhouseUpdateSSHTunnelMethod `json:"tunnel_method,omitempty"`
	// The username which is used to access the database.
	Username string `json:"username"`
}

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

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

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

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

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

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

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

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

func (o *SourceClickhouseUpdate) GetTunnelMethod() *SourceClickhouseUpdateSSHTunnelMethod {
	if o == nil {
		return nil
	}
	return o.TunnelMethod
}

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