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

const (
	DestinationSnowflakeUpdateSchemasCredentialsAuthTypeOAuth20 DestinationSnowflakeUpdateSchemasCredentialsAuthType = "OAuth2.0"
)

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

type DestinationSnowflakeUpdateOAuth20 struct {
	// Enter you application's Access Token
	AccessToken string                                                `json:"access_token"`
	authType    *DestinationSnowflakeUpdateSchemasCredentialsAuthType `const:"OAuth2.0" json:"auth_type"`
	// Enter your application's Client ID
	ClientID *string `json:"client_id,omitempty"`
	// Enter your application's Client secret
	ClientSecret *string `json:"client_secret,omitempty"`
	// Enter your application's Refresh Token
	RefreshToken string `json:"refresh_token"`
}

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

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

func (o *DestinationSnowflakeUpdateOAuth20) GetAccessToken() string {
	if o == nil {
		return ""
	}
	return o.AccessToken
}

func (o *DestinationSnowflakeUpdateOAuth20) GetAuthType() *DestinationSnowflakeUpdateSchemasCredentialsAuthType {
	return DestinationSnowflakeUpdateSchemasCredentialsAuthTypeOAuth20.ToPointer()
}

func (o *DestinationSnowflakeUpdateOAuth20) GetClientID() *string {
	if o == nil {
		return nil
	}
	return o.ClientID
}

func (o *DestinationSnowflakeUpdateOAuth20) GetClientSecret() *string {
	if o == nil {
		return nil
	}
	return o.ClientSecret
}

func (o *DestinationSnowflakeUpdateOAuth20) GetRefreshToken() string {
	if o == nil {
		return ""
	}
	return o.RefreshToken
}

type DestinationSnowflakeUpdateSchemasAuthType string

const (
	DestinationSnowflakeUpdateSchemasAuthTypeUsernameAndPassword DestinationSnowflakeUpdateSchemasAuthType = "Username and Password"
)

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

type DestinationSnowflakeUpdateUsernameAndPassword struct {
	authType *DestinationSnowflakeUpdateSchemasAuthType `const:"Username and Password" json:"auth_type"`
	// Enter the password associated with the username.
	Password string `json:"password"`
}

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

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

func (o *DestinationSnowflakeUpdateUsernameAndPassword) GetAuthType() *DestinationSnowflakeUpdateSchemasAuthType {
	return DestinationSnowflakeUpdateSchemasAuthTypeUsernameAndPassword.ToPointer()
}

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

type DestinationSnowflakeUpdateAuthType string

const (
	DestinationSnowflakeUpdateAuthTypeKeyPairAuthentication DestinationSnowflakeUpdateAuthType = "Key Pair Authentication"
)

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

type DestinationSnowflakeUpdateKeyPairAuthentication struct {
	authType *DestinationSnowflakeUpdateAuthType `const:"Key Pair Authentication" json:"auth_type"`
	// RSA Private key to use for Snowflake connection. See the <a href="https://docs.airbyte.com/integrations/destinations/snowflake">docs</a> for more information on how to obtain this key.
	PrivateKey string `json:"private_key"`
	// Passphrase for private key
	PrivateKeyPassword *string `json:"private_key_password,omitempty"`
}

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

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

func (o *DestinationSnowflakeUpdateKeyPairAuthentication) GetAuthType() *DestinationSnowflakeUpdateAuthType {
	return DestinationSnowflakeUpdateAuthTypeKeyPairAuthentication.ToPointer()
}

func (o *DestinationSnowflakeUpdateKeyPairAuthentication) GetPrivateKey() string {
	if o == nil {
		return ""
	}
	return o.PrivateKey
}

func (o *DestinationSnowflakeUpdateKeyPairAuthentication) GetPrivateKeyPassword() *string {
	if o == nil {
		return nil
	}
	return o.PrivateKeyPassword
}

type DestinationSnowflakeUpdateAuthorizationMethodType string

const (
	DestinationSnowflakeUpdateAuthorizationMethodTypeDestinationSnowflakeUpdateKeyPairAuthentication DestinationSnowflakeUpdateAuthorizationMethodType = "destination-snowflake-update_Key Pair Authentication"
	DestinationSnowflakeUpdateAuthorizationMethodTypeDestinationSnowflakeUpdateUsernameAndPassword   DestinationSnowflakeUpdateAuthorizationMethodType = "destination-snowflake-update_Username and Password"
	DestinationSnowflakeUpdateAuthorizationMethodTypeDestinationSnowflakeUpdateOAuth20               DestinationSnowflakeUpdateAuthorizationMethodType = "destination-snowflake-update_OAuth2.0"
)

type DestinationSnowflakeUpdateAuthorizationMethod struct {
	DestinationSnowflakeUpdateKeyPairAuthentication *DestinationSnowflakeUpdateKeyPairAuthentication `queryParam:"inline"`
	DestinationSnowflakeUpdateUsernameAndPassword   *DestinationSnowflakeUpdateUsernameAndPassword   `queryParam:"inline"`
	DestinationSnowflakeUpdateOAuth20               *DestinationSnowflakeUpdateOAuth20               `queryParam:"inline"`

	Type DestinationSnowflakeUpdateAuthorizationMethodType
}

func CreateDestinationSnowflakeUpdateAuthorizationMethodDestinationSnowflakeUpdateKeyPairAuthentication(destinationSnowflakeUpdateKeyPairAuthentication DestinationSnowflakeUpdateKeyPairAuthentication) DestinationSnowflakeUpdateAuthorizationMethod {
	typ := DestinationSnowflakeUpdateAuthorizationMethodTypeDestinationSnowflakeUpdateKeyPairAuthentication

	return DestinationSnowflakeUpdateAuthorizationMethod{
		DestinationSnowflakeUpdateKeyPairAuthentication: &destinationSnowflakeUpdateKeyPairAuthentication,
		Type: typ,
	}
}

func CreateDestinationSnowflakeUpdateAuthorizationMethodDestinationSnowflakeUpdateUsernameAndPassword(destinationSnowflakeUpdateUsernameAndPassword DestinationSnowflakeUpdateUsernameAndPassword) DestinationSnowflakeUpdateAuthorizationMethod {
	typ := DestinationSnowflakeUpdateAuthorizationMethodTypeDestinationSnowflakeUpdateUsernameAndPassword

	return DestinationSnowflakeUpdateAuthorizationMethod{
		DestinationSnowflakeUpdateUsernameAndPassword: &destinationSnowflakeUpdateUsernameAndPassword,
		Type: typ,
	}
}

func CreateDestinationSnowflakeUpdateAuthorizationMethodDestinationSnowflakeUpdateOAuth20(destinationSnowflakeUpdateOAuth20 DestinationSnowflakeUpdateOAuth20) DestinationSnowflakeUpdateAuthorizationMethod {
	typ := DestinationSnowflakeUpdateAuthorizationMethodTypeDestinationSnowflakeUpdateOAuth20

	return DestinationSnowflakeUpdateAuthorizationMethod{
		DestinationSnowflakeUpdateOAuth20: &destinationSnowflakeUpdateOAuth20,
		Type:                              typ,
	}
}

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

	var destinationSnowflakeUpdateUsernameAndPassword DestinationSnowflakeUpdateUsernameAndPassword = DestinationSnowflakeUpdateUsernameAndPassword{}
	if err := utils.UnmarshalJSON(data, &destinationSnowflakeUpdateUsernameAndPassword, "", true, true); err == nil {
		u.DestinationSnowflakeUpdateUsernameAndPassword = &destinationSnowflakeUpdateUsernameAndPassword
		u.Type = DestinationSnowflakeUpdateAuthorizationMethodTypeDestinationSnowflakeUpdateUsernameAndPassword
		return nil
	}

	var destinationSnowflakeUpdateKeyPairAuthentication DestinationSnowflakeUpdateKeyPairAuthentication = DestinationSnowflakeUpdateKeyPairAuthentication{}
	if err := utils.UnmarshalJSON(data, &destinationSnowflakeUpdateKeyPairAuthentication, "", true, true); err == nil {
		u.DestinationSnowflakeUpdateKeyPairAuthentication = &destinationSnowflakeUpdateKeyPairAuthentication
		u.Type = DestinationSnowflakeUpdateAuthorizationMethodTypeDestinationSnowflakeUpdateKeyPairAuthentication
		return nil
	}

	var destinationSnowflakeUpdateOAuth20 DestinationSnowflakeUpdateOAuth20 = DestinationSnowflakeUpdateOAuth20{}
	if err := utils.UnmarshalJSON(data, &destinationSnowflakeUpdateOAuth20, "", true, true); err == nil {
		u.DestinationSnowflakeUpdateOAuth20 = &destinationSnowflakeUpdateOAuth20
		u.Type = DestinationSnowflakeUpdateAuthorizationMethodTypeDestinationSnowflakeUpdateOAuth20
		return nil
	}

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

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

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

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

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

type DestinationSnowflakeUpdate struct {
	Credentials *DestinationSnowflakeUpdateAuthorizationMethod `json:"credentials,omitempty"`
	// Enter the name of the <a href="https://docs.snowflake.com/en/sql-reference/ddl-database.html#database-schema-share-ddl">database</a> you want to sync data into
	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"`
	// Enter your Snowflake account's <a href="https://docs.snowflake.com/en/user-guide/admin-account-identifier.html#using-an-account-locator-as-an-identifier">locator</a> (in the format <account_locator>.<region>.<cloud>.snowflakecomputing.com)
	Host string `json:"host"`
	// Enter the 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"`
	// The schema to write raw tables into (default: airbyte_internal)
	RawDataSchema *string `json:"raw_data_schema,omitempty"`
	// The number of days of Snowflake Time Travel to enable on the tables. See <a href="https://docs.snowflake.com/en/user-guide/data-time-travel#data-retention-period">Snowflake's documentation</a> for more information. Setting a nonzero value will incur increased storage costs in your Snowflake instance.
	RetentionPeriodDays *int64 `default:"1" json:"retention_period_days"`
	// Enter the <a href="https://docs.snowflake.com/en/user-guide/security-access-control-overview.html#roles">role</a> that you want to use to access Snowflake
	Role string `json:"role"`
	// Enter the name of the default <a href="https://docs.snowflake.com/en/sql-reference/ddl-database.html#database-schema-share-ddl">schema</a>
	Schema string `json:"schema"`
	// Use MERGE for de-duplication of final tables. This option no effect if Final tables are disabled or Sync mode is not DEDUPE
	UseMergeForUpsert *bool `default:"false" json:"use_merge_for_upsert"`
	// Enter the name of the user you want to use to access the database
	Username string `json:"username"`
	// Enter the name of the <a href="https://docs.snowflake.com/en/user-guide/warehouses-overview.html#overview-of-warehouses">warehouse</a> that you want to use as a compute cluster
	Warehouse string `json:"warehouse"`
}

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

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

func (o *DestinationSnowflakeUpdate) GetCredentials() *DestinationSnowflakeUpdateAuthorizationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

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

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

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

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

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

func (o *DestinationSnowflakeUpdate) GetRetentionPeriodDays() *int64 {
	if o == nil {
		return nil
	}
	return o.RetentionPeriodDays
}

func (o *DestinationSnowflakeUpdate) GetRole() string {
	if o == nil {
		return ""
	}
	return o.Role
}

func (o *DestinationSnowflakeUpdate) GetSchema() string {
	if o == nil {
		return ""
	}
	return o.Schema
}

func (o *DestinationSnowflakeUpdate) GetUseMergeForUpsert() *bool {
	if o == nil {
		return nil
	}
	return o.UseMergeForUpsert
}

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

func (o *DestinationSnowflakeUpdate) GetWarehouse() string {
	if o == nil {
		return ""
	}
	return o.Warehouse
}
