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

// DatasetLocation - The location of the dataset. Warning: Changes made after creation will not be applied. Read more <a href="https://cloud.google.com/bigquery/docs/locations">here</a>.
type DatasetLocation string

const (
	DatasetLocationUs                     DatasetLocation = "US"
	DatasetLocationEu                     DatasetLocation = "EU"
	DatasetLocationAsiaEast1              DatasetLocation = "asia-east1"
	DatasetLocationAsiaEast2              DatasetLocation = "asia-east2"
	DatasetLocationAsiaNortheast1         DatasetLocation = "asia-northeast1"
	DatasetLocationAsiaNortheast2         DatasetLocation = "asia-northeast2"
	DatasetLocationAsiaNortheast3         DatasetLocation = "asia-northeast3"
	DatasetLocationAsiaSouth1             DatasetLocation = "asia-south1"
	DatasetLocationAsiaSouth2             DatasetLocation = "asia-south2"
	DatasetLocationAsiaSoutheast1         DatasetLocation = "asia-southeast1"
	DatasetLocationAsiaSoutheast2         DatasetLocation = "asia-southeast2"
	DatasetLocationAustraliaSoutheast1    DatasetLocation = "australia-southeast1"
	DatasetLocationAustraliaSoutheast2    DatasetLocation = "australia-southeast2"
	DatasetLocationEuropeCentral1         DatasetLocation = "europe-central1"
	DatasetLocationEuropeCentral2         DatasetLocation = "europe-central2"
	DatasetLocationEuropeNorth1           DatasetLocation = "europe-north1"
	DatasetLocationEuropeNorth2           DatasetLocation = "europe-north2"
	DatasetLocationEuropeSouthwest1       DatasetLocation = "europe-southwest1"
	DatasetLocationEuropeWest1            DatasetLocation = "europe-west1"
	DatasetLocationEuropeWest2            DatasetLocation = "europe-west2"
	DatasetLocationEuropeWest3            DatasetLocation = "europe-west3"
	DatasetLocationEuropeWest4            DatasetLocation = "europe-west4"
	DatasetLocationEuropeWest6            DatasetLocation = "europe-west6"
	DatasetLocationEuropeWest7            DatasetLocation = "europe-west7"
	DatasetLocationEuropeWest8            DatasetLocation = "europe-west8"
	DatasetLocationEuropeWest9            DatasetLocation = "europe-west9"
	DatasetLocationEuropeWest12           DatasetLocation = "europe-west12"
	DatasetLocationMeCentral1             DatasetLocation = "me-central1"
	DatasetLocationMeCentral2             DatasetLocation = "me-central2"
	DatasetLocationMeWest1                DatasetLocation = "me-west1"
	DatasetLocationNorthamericaNortheast1 DatasetLocation = "northamerica-northeast1"
	DatasetLocationNorthamericaNortheast2 DatasetLocation = "northamerica-northeast2"
	DatasetLocationSouthamericaEast1      DatasetLocation = "southamerica-east1"
	DatasetLocationSouthamericaWest1      DatasetLocation = "southamerica-west1"
	DatasetLocationUsCentral1             DatasetLocation = "us-central1"
	DatasetLocationUsEast1                DatasetLocation = "us-east1"
	DatasetLocationUsEast2                DatasetLocation = "us-east2"
	DatasetLocationUsEast3                DatasetLocation = "us-east3"
	DatasetLocationUsEast4                DatasetLocation = "us-east4"
	DatasetLocationUsEast5                DatasetLocation = "us-east5"
	DatasetLocationUsSouth1               DatasetLocation = "us-south1"
	DatasetLocationUsWest1                DatasetLocation = "us-west1"
	DatasetLocationUsWest2                DatasetLocation = "us-west2"
	DatasetLocationUsWest3                DatasetLocation = "us-west3"
	DatasetLocationUsWest4                DatasetLocation = "us-west4"
)

func (e DatasetLocation) ToPointer() *DatasetLocation {
	return &e
}
func (e *DatasetLocation) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "US":
		fallthrough
	case "EU":
		fallthrough
	case "asia-east1":
		fallthrough
	case "asia-east2":
		fallthrough
	case "asia-northeast1":
		fallthrough
	case "asia-northeast2":
		fallthrough
	case "asia-northeast3":
		fallthrough
	case "asia-south1":
		fallthrough
	case "asia-south2":
		fallthrough
	case "asia-southeast1":
		fallthrough
	case "asia-southeast2":
		fallthrough
	case "australia-southeast1":
		fallthrough
	case "australia-southeast2":
		fallthrough
	case "europe-central1":
		fallthrough
	case "europe-central2":
		fallthrough
	case "europe-north1":
		fallthrough
	case "europe-north2":
		fallthrough
	case "europe-southwest1":
		fallthrough
	case "europe-west1":
		fallthrough
	case "europe-west2":
		fallthrough
	case "europe-west3":
		fallthrough
	case "europe-west4":
		fallthrough
	case "europe-west6":
		fallthrough
	case "europe-west7":
		fallthrough
	case "europe-west8":
		fallthrough
	case "europe-west9":
		fallthrough
	case "europe-west12":
		fallthrough
	case "me-central1":
		fallthrough
	case "me-central2":
		fallthrough
	case "me-west1":
		fallthrough
	case "northamerica-northeast1":
		fallthrough
	case "northamerica-northeast2":
		fallthrough
	case "southamerica-east1":
		fallthrough
	case "southamerica-west1":
		fallthrough
	case "us-central1":
		fallthrough
	case "us-east1":
		fallthrough
	case "us-east2":
		fallthrough
	case "us-east3":
		fallthrough
	case "us-east4":
		fallthrough
	case "us-east5":
		fallthrough
	case "us-south1":
		fallthrough
	case "us-west1":
		fallthrough
	case "us-west2":
		fallthrough
	case "us-west3":
		fallthrough
	case "us-west4":
		*e = DatasetLocation(v)
		return nil
	default:
		return fmt.Errorf("invalid value for DatasetLocation: %v", v)
	}
}

type DestinationBigqueryCredentialType string

const (
	DestinationBigqueryCredentialTypeHmacKey DestinationBigqueryCredentialType = "HMAC_KEY"
)

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

type DestinationBigqueryHMACKey struct {
	credentialType DestinationBigqueryCredentialType `const:"HMAC_KEY" json:"credential_type"`
	// HMAC key access ID. When linked to a service account, this ID is 61 characters long; when linked to a user account, it is 24 characters long.
	HmacKeyAccessID string `json:"hmac_key_access_id"`
	// The corresponding secret for the access ID. It is a 40-character base-64 encoded string.
	HmacKeySecret string `json:"hmac_key_secret"`
}

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

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

func (o *DestinationBigqueryHMACKey) GetCredentialType() DestinationBigqueryCredentialType {
	return DestinationBigqueryCredentialTypeHmacKey
}

func (o *DestinationBigqueryHMACKey) GetHmacKeyAccessID() string {
	if o == nil {
		return ""
	}
	return o.HmacKeyAccessID
}

func (o *DestinationBigqueryHMACKey) GetHmacKeySecret() string {
	if o == nil {
		return ""
	}
	return o.HmacKeySecret
}

type CredentialUnionType string

const (
	CredentialUnionTypeDestinationBigqueryHMACKey CredentialUnionType = "destination-bigquery_HMAC key"
)

// Credential - An HMAC key is a type of credential and can be associated with a service account or a user account in Cloud Storage. Read more <a href="https://cloud.google.com/storage/docs/authentication/hmackeys">here</a>.
type Credential struct {
	DestinationBigqueryHMACKey *DestinationBigqueryHMACKey `queryParam:"inline"`

	Type CredentialUnionType
}

func CreateCredentialDestinationBigqueryHMACKey(destinationBigqueryHMACKey DestinationBigqueryHMACKey) Credential {
	typ := CredentialUnionTypeDestinationBigqueryHMACKey

	return Credential{
		DestinationBigqueryHMACKey: &destinationBigqueryHMACKey,
		Type:                       typ,
	}
}

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

	var destinationBigqueryHMACKey DestinationBigqueryHMACKey = DestinationBigqueryHMACKey{}
	if err := utils.UnmarshalJSON(data, &destinationBigqueryHMACKey, "", true, true); err == nil {
		u.DestinationBigqueryHMACKey = &destinationBigqueryHMACKey
		u.Type = CredentialUnionTypeDestinationBigqueryHMACKey
		return nil
	}

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

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

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

// GCSTmpFilesAfterwardProcessing - This upload method is supposed to temporary store records in GCS bucket. By this select you can chose if these records should be removed from GCS when migration has finished. The default "Delete all tmp files from GCS" value is used if not set explicitly.
type GCSTmpFilesAfterwardProcessing string

const (
	GCSTmpFilesAfterwardProcessingDeleteAllTmpFilesFromGcs GCSTmpFilesAfterwardProcessing = "Delete all tmp files from GCS"
	GCSTmpFilesAfterwardProcessingKeepAllTmpFilesInGcs     GCSTmpFilesAfterwardProcessing = "Keep all tmp files in GCS"
)

func (e GCSTmpFilesAfterwardProcessing) ToPointer() *GCSTmpFilesAfterwardProcessing {
	return &e
}
func (e *GCSTmpFilesAfterwardProcessing) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "Delete all tmp files from GCS":
		fallthrough
	case "Keep all tmp files in GCS":
		*e = GCSTmpFilesAfterwardProcessing(v)
		return nil
	default:
		return fmt.Errorf("invalid value for GCSTmpFilesAfterwardProcessing: %v", v)
	}
}

type DestinationBigquerySchemasMethod string

const (
	DestinationBigquerySchemasMethodGcsStaging DestinationBigquerySchemasMethod = "GCS Staging"
)

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

// GCSStaging - Writes large batches of records to a file, uploads the file to GCS, then uses COPY INTO to load your data into BigQuery.
type GCSStaging struct {
	// An HMAC key is a type of credential and can be associated with a service account or a user account in Cloud Storage. Read more <a href="https://cloud.google.com/storage/docs/authentication/hmackeys">here</a>.
	Credential Credential `json:"credential"`
	// The name of the GCS bucket. Read more <a href="https://cloud.google.com/storage/docs/naming-buckets">here</a>.
	GcsBucketName string `json:"gcs_bucket_name"`
	// Directory under the GCS bucket where data will be written.
	GcsBucketPath string `json:"gcs_bucket_path"`
	// This upload method is supposed to temporary store records in GCS bucket. By this select you can chose if these records should be removed from GCS when migration has finished. The default "Delete all tmp files from GCS" value is used if not set explicitly.
	KeepFilesInGcsBucket *GCSTmpFilesAfterwardProcessing  `default:"Delete all tmp files from GCS" json:"keep_files_in_gcs-bucket"`
	method               DestinationBigquerySchemasMethod `const:"GCS Staging" json:"method"`
}

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

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

func (o *GCSStaging) GetCredential() Credential {
	if o == nil {
		return Credential{}
	}
	return o.Credential
}

func (o *GCSStaging) GetGcsBucketName() string {
	if o == nil {
		return ""
	}
	return o.GcsBucketName
}

func (o *GCSStaging) GetGcsBucketPath() string {
	if o == nil {
		return ""
	}
	return o.GcsBucketPath
}

func (o *GCSStaging) GetKeepFilesInGcsBucket() *GCSTmpFilesAfterwardProcessing {
	if o == nil {
		return nil
	}
	return o.KeepFilesInGcsBucket
}

func (o *GCSStaging) GetMethod() DestinationBigquerySchemasMethod {
	return DestinationBigquerySchemasMethodGcsStaging
}

type DestinationBigqueryMethod string

const (
	DestinationBigqueryMethodStandard DestinationBigqueryMethod = "Standard"
)

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

// BatchedStandardInserts - Direct loading using batched SQL INSERT statements. This method uses the BigQuery driver to convert large INSERT statements into file uploads automatically.
type BatchedStandardInserts struct {
	method DestinationBigqueryMethod `const:"Standard" json:"method"`
}

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

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

func (o *BatchedStandardInserts) GetMethod() DestinationBigqueryMethod {
	return DestinationBigqueryMethodStandard
}

type LoadingMethodType string

const (
	LoadingMethodTypeBatchedStandardInserts LoadingMethodType = "Batched Standard Inserts"
	LoadingMethodTypeGCSStaging             LoadingMethodType = "GCS Staging"
)

// LoadingMethod - The way data will be uploaded to BigQuery.
type LoadingMethod struct {
	BatchedStandardInserts *BatchedStandardInserts `queryParam:"inline"`
	GCSStaging             *GCSStaging             `queryParam:"inline"`

	Type LoadingMethodType
}

func CreateLoadingMethodBatchedStandardInserts(batchedStandardInserts BatchedStandardInserts) LoadingMethod {
	typ := LoadingMethodTypeBatchedStandardInserts

	return LoadingMethod{
		BatchedStandardInserts: &batchedStandardInserts,
		Type:                   typ,
	}
}

func CreateLoadingMethodGCSStaging(gcsStaging GCSStaging) LoadingMethod {
	typ := LoadingMethodTypeGCSStaging

	return LoadingMethod{
		GCSStaging: &gcsStaging,
		Type:       typ,
	}
}

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

	var batchedStandardInserts BatchedStandardInserts = BatchedStandardInserts{}
	if err := utils.UnmarshalJSON(data, &batchedStandardInserts, "", true, true); err == nil {
		u.BatchedStandardInserts = &batchedStandardInserts
		u.Type = LoadingMethodTypeBatchedStandardInserts
		return nil
	}

	var gcsStaging GCSStaging = GCSStaging{}
	if err := utils.UnmarshalJSON(data, &gcsStaging, "", true, true); err == nil {
		u.GCSStaging = &gcsStaging
		u.Type = LoadingMethodTypeGCSStaging
		return nil
	}

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

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

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

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

// TransformationQueryRunType - Interactive run type means that the query is executed as soon as possible, and these queries count towards concurrent rate limit and daily limit. Read more about interactive run type <a href="https://cloud.google.com/bigquery/docs/running-queries#queries">here</a>. Batch queries are queued and started as soon as idle resources are available in the BigQuery shared resource pool, which usually occurs within a few minutes. Batch queries don’t count towards your concurrent rate limit. Read more about batch queries <a href="https://cloud.google.com/bigquery/docs/running-queries#batch">here</a>. The default "interactive" value is used if not set explicitly.
type TransformationQueryRunType string

const (
	TransformationQueryRunTypeInteractive TransformationQueryRunType = "interactive"
	TransformationQueryRunTypeBatch       TransformationQueryRunType = "batch"
)

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

type DestinationBigqueryBigquery string

const (
	DestinationBigqueryBigqueryBigquery DestinationBigqueryBigquery = "bigquery"
)

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

type DestinationBigquery struct {
	// Google BigQuery client's chunk (buffer) size (MIN=1, MAX = 15) for each table. The size that will be written by a single RPC. Written data will be buffered and only flushed upon reaching this size or closing the channel. The default 15MB value is used if not set explicitly. Read more <a href="https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.client.Client.html">here</a>.
	BigQueryClientBufferSizeMb *int64 `default:"15" json:"big_query_client_buffer_size_mb"`
	// The contents of the JSON service account key. Check out the <a href="https://docs.airbyte.com/integrations/destinations/bigquery#service-account-key">docs</a> if you need help generating this key. Default credentials will be used if this field is left empty.
	CredentialsJSON *string `json:"credentials_json,omitempty"`
	// The default BigQuery Dataset ID that tables are replicated to if the source does not specify a namespace. Read more <a href="https://cloud.google.com/bigquery/docs/datasets#create-dataset">here</a>.
	DatasetID string `json:"dataset_id"`
	// The location of the dataset. Warning: Changes made after creation will not be applied. Read more <a href="https://cloud.google.com/bigquery/docs/locations">here</a>.
	DatasetLocation DatasetLocation `json:"dataset_location"`
	// 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"`
	// The way data will be uploaded to BigQuery.
	LoadingMethod *LoadingMethod `json:"loading_method,omitempty"`
	// The GCP project ID for the project containing the target BigQuery dataset. Read more <a href="https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects">here</a>.
	ProjectID string `json:"project_id"`
	// The dataset to write raw tables into (default: airbyte_internal)
	RawDataDataset *string `json:"raw_data_dataset,omitempty"`
	// Interactive run type means that the query is executed as soon as possible, and these queries count towards concurrent rate limit and daily limit. Read more about interactive run type <a href="https://cloud.google.com/bigquery/docs/running-queries#queries">here</a>. Batch queries are queued and started as soon as idle resources are available in the BigQuery shared resource pool, which usually occurs within a few minutes. Batch queries don’t count towards your concurrent rate limit. Read more about batch queries <a href="https://cloud.google.com/bigquery/docs/running-queries#batch">here</a>. The default "interactive" value is used if not set explicitly.
	TransformationPriority *TransformationQueryRunType `default:"interactive" json:"transformation_priority"`
	destinationType        DestinationBigqueryBigquery `const:"bigquery" json:"destinationType"`
}

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

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

func (o *DestinationBigquery) GetBigQueryClientBufferSizeMb() *int64 {
	if o == nil {
		return nil
	}
	return o.BigQueryClientBufferSizeMb
}

func (o *DestinationBigquery) GetCredentialsJSON() *string {
	if o == nil {
		return nil
	}
	return o.CredentialsJSON
}

func (o *DestinationBigquery) GetDatasetID() string {
	if o == nil {
		return ""
	}
	return o.DatasetID
}

func (o *DestinationBigquery) GetDatasetLocation() DatasetLocation {
	if o == nil {
		return DatasetLocation("")
	}
	return o.DatasetLocation
}

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

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

func (o *DestinationBigquery) GetProjectID() string {
	if o == nil {
		return ""
	}
	return o.ProjectID
}

func (o *DestinationBigquery) GetRawDataDataset() *string {
	if o == nil {
		return nil
	}
	return o.RawDataDataset
}

func (o *DestinationBigquery) GetTransformationPriority() *TransformationQueryRunType {
	if o == nil {
		return nil
	}
	return o.TransformationPriority
}

func (o *DestinationBigquery) GetDestinationType() DestinationBigqueryBigquery {
	return DestinationBigqueryBigqueryBigquery
}
