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

const (
	DestinationFireboltUpdateSchemasMethodS3 DestinationFireboltUpdateSchemasMethod = "S3"
)

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

type DestinationFireboltUpdateExternalTableViaS3 struct {
	// AWS access key granting read and write access to S3.
	AwsKeyID string `json:"aws_key_id"`
	// Corresponding secret part of the AWS Key
	AwsKeySecret string                                 `json:"aws_key_secret"`
	method       DestinationFireboltUpdateSchemasMethod `const:"S3" json:"method"`
	// The name of the S3 bucket.
	S3Bucket string `json:"s3_bucket"`
	// Region name of the S3 bucket.
	S3Region string `json:"s3_region"`
}

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

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

func (o *DestinationFireboltUpdateExternalTableViaS3) GetAwsKeyID() string {
	if o == nil {
		return ""
	}
	return o.AwsKeyID
}

func (o *DestinationFireboltUpdateExternalTableViaS3) GetAwsKeySecret() string {
	if o == nil {
		return ""
	}
	return o.AwsKeySecret
}

func (o *DestinationFireboltUpdateExternalTableViaS3) GetMethod() DestinationFireboltUpdateSchemasMethod {
	return DestinationFireboltUpdateSchemasMethodS3
}

func (o *DestinationFireboltUpdateExternalTableViaS3) GetS3Bucket() string {
	if o == nil {
		return ""
	}
	return o.S3Bucket
}

func (o *DestinationFireboltUpdateExternalTableViaS3) GetS3Region() string {
	if o == nil {
		return ""
	}
	return o.S3Region
}

type DestinationFireboltUpdateMethod string

const (
	DestinationFireboltUpdateMethodSQL DestinationFireboltUpdateMethod = "SQL"
)

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

type DestinationFireboltUpdateSQLInserts struct {
	method DestinationFireboltUpdateMethod `const:"SQL" json:"method"`
}

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

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

func (o *DestinationFireboltUpdateSQLInserts) GetMethod() DestinationFireboltUpdateMethod {
	return DestinationFireboltUpdateMethodSQL
}

type DestinationFireboltUpdateLoadingMethodType string

const (
	DestinationFireboltUpdateLoadingMethodTypeDestinationFireboltUpdateSQLInserts         DestinationFireboltUpdateLoadingMethodType = "destination-firebolt-update_SQL Inserts"
	DestinationFireboltUpdateLoadingMethodTypeDestinationFireboltUpdateExternalTableViaS3 DestinationFireboltUpdateLoadingMethodType = "destination-firebolt-update_External Table via S3"
)

// DestinationFireboltUpdateLoadingMethod - Loading method used to select the way data will be uploaded to Firebolt
type DestinationFireboltUpdateLoadingMethod struct {
	DestinationFireboltUpdateSQLInserts         *DestinationFireboltUpdateSQLInserts         `queryParam:"inline"`
	DestinationFireboltUpdateExternalTableViaS3 *DestinationFireboltUpdateExternalTableViaS3 `queryParam:"inline"`

	Type DestinationFireboltUpdateLoadingMethodType
}

func CreateDestinationFireboltUpdateLoadingMethodDestinationFireboltUpdateSQLInserts(destinationFireboltUpdateSQLInserts DestinationFireboltUpdateSQLInserts) DestinationFireboltUpdateLoadingMethod {
	typ := DestinationFireboltUpdateLoadingMethodTypeDestinationFireboltUpdateSQLInserts

	return DestinationFireboltUpdateLoadingMethod{
		DestinationFireboltUpdateSQLInserts: &destinationFireboltUpdateSQLInserts,
		Type:                                typ,
	}
}

func CreateDestinationFireboltUpdateLoadingMethodDestinationFireboltUpdateExternalTableViaS3(destinationFireboltUpdateExternalTableViaS3 DestinationFireboltUpdateExternalTableViaS3) DestinationFireboltUpdateLoadingMethod {
	typ := DestinationFireboltUpdateLoadingMethodTypeDestinationFireboltUpdateExternalTableViaS3

	return DestinationFireboltUpdateLoadingMethod{
		DestinationFireboltUpdateExternalTableViaS3: &destinationFireboltUpdateExternalTableViaS3,
		Type: typ,
	}
}

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

	var destinationFireboltUpdateSQLInserts DestinationFireboltUpdateSQLInserts = DestinationFireboltUpdateSQLInserts{}
	if err := utils.UnmarshalJSON(data, &destinationFireboltUpdateSQLInserts, "", true, true); err == nil {
		u.DestinationFireboltUpdateSQLInserts = &destinationFireboltUpdateSQLInserts
		u.Type = DestinationFireboltUpdateLoadingMethodTypeDestinationFireboltUpdateSQLInserts
		return nil
	}

	var destinationFireboltUpdateExternalTableViaS3 DestinationFireboltUpdateExternalTableViaS3 = DestinationFireboltUpdateExternalTableViaS3{}
	if err := utils.UnmarshalJSON(data, &destinationFireboltUpdateExternalTableViaS3, "", true, true); err == nil {
		u.DestinationFireboltUpdateExternalTableViaS3 = &destinationFireboltUpdateExternalTableViaS3
		u.Type = DestinationFireboltUpdateLoadingMethodTypeDestinationFireboltUpdateExternalTableViaS3
		return nil
	}

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

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

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

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

type DestinationFireboltUpdate struct {
	// Firebolt account to login.
	Account string `json:"account"`
	// Firebolt service account ID.
	ClientID string `json:"client_id"`
	// Firebolt secret, corresponding to the service account ID.
	ClientSecret string `json:"client_secret"`
	// The database to connect to.
	Database string `json:"database"`
	// Engine name to connect to.
	Engine string `json:"engine"`
	// The host name of your Firebolt database.
	Host *string `json:"host,omitempty"`
	// Loading method used to select the way data will be uploaded to Firebolt
	LoadingMethod *DestinationFireboltUpdateLoadingMethod `json:"loading_method,omitempty"`
}

func (o *DestinationFireboltUpdate) GetAccount() string {
	if o == nil {
		return ""
	}
	return o.Account
}

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

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

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

func (o *DestinationFireboltUpdate) GetEngine() string {
	if o == nil {
		return ""
	}
	return o.Engine
}

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

func (o *DestinationFireboltUpdate) GetLoadingMethod() *DestinationFireboltUpdateLoadingMethod {
	if o == nil {
		return nil
	}
	return o.LoadingMethod
}
