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

const (
	DestinationAzureBlobStorageUpdateSchemasFlatteningNoFlattening        DestinationAzureBlobStorageUpdateSchemasFlattening = "No flattening"
	DestinationAzureBlobStorageUpdateSchemasFlatteningRootLevelFlattening DestinationAzureBlobStorageUpdateSchemasFlattening = "Root level flattening"
)

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

type DestinationAzureBlobStorageUpdateSchemasFormatType string

const (
	DestinationAzureBlobStorageUpdateSchemasFormatTypeJsonl DestinationAzureBlobStorageUpdateSchemasFormatType = "JSONL"
)

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

type DestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON struct {
	Flattening           *DestinationAzureBlobStorageUpdateSchemasFlattening `default:"No flattening" json:"flattening"`
	FormatType           *DestinationAzureBlobStorageUpdateSchemasFormatType `default:"JSONL" json:"format_type"`
	AdditionalProperties any                                                 `additionalProperties:"true" json:"-"`
}

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

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

func (o *DestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON) GetFlattening() *DestinationAzureBlobStorageUpdateSchemasFlattening {
	if o == nil {
		return nil
	}
	return o.Flattening
}

func (o *DestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON) GetFormatType() *DestinationAzureBlobStorageUpdateSchemasFormatType {
	if o == nil {
		return nil
	}
	return o.FormatType
}

func (o *DestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON) GetAdditionalProperties() any {
	if o == nil {
		return nil
	}
	return o.AdditionalProperties
}

type DestinationAzureBlobStorageUpdateFlattening string

const (
	DestinationAzureBlobStorageUpdateFlatteningNoFlattening        DestinationAzureBlobStorageUpdateFlattening = "No flattening"
	DestinationAzureBlobStorageUpdateFlatteningRootLevelFlattening DestinationAzureBlobStorageUpdateFlattening = "Root level flattening"
)

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

type DestinationAzureBlobStorageUpdateFormatType string

const (
	DestinationAzureBlobStorageUpdateFormatTypeCsv DestinationAzureBlobStorageUpdateFormatType = "CSV"
)

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

type DestinationAzureBlobStorageUpdateCSVCommaSeparatedValues struct {
	Flattening           *DestinationAzureBlobStorageUpdateFlattening `default:"No flattening" json:"flattening"`
	FormatType           *DestinationAzureBlobStorageUpdateFormatType `default:"CSV" json:"format_type"`
	AdditionalProperties any                                          `additionalProperties:"true" json:"-"`
}

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

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

func (o *DestinationAzureBlobStorageUpdateCSVCommaSeparatedValues) GetFlattening() *DestinationAzureBlobStorageUpdateFlattening {
	if o == nil {
		return nil
	}
	return o.Flattening
}

func (o *DestinationAzureBlobStorageUpdateCSVCommaSeparatedValues) GetFormatType() *DestinationAzureBlobStorageUpdateFormatType {
	if o == nil {
		return nil
	}
	return o.FormatType
}

func (o *DestinationAzureBlobStorageUpdateCSVCommaSeparatedValues) GetAdditionalProperties() any {
	if o == nil {
		return nil
	}
	return o.AdditionalProperties
}

type DestinationAzureBlobStorageUpdateOutputFormatType string

const (
	DestinationAzureBlobStorageUpdateOutputFormatTypeDestinationAzureBlobStorageUpdateCSVCommaSeparatedValues       DestinationAzureBlobStorageUpdateOutputFormatType = "destination-azure-blob-storage-update_CSV: Comma-Separated Values"
	DestinationAzureBlobStorageUpdateOutputFormatTypeDestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON DestinationAzureBlobStorageUpdateOutputFormatType = "destination-azure-blob-storage-update_JSON Lines: Newline-delimited JSON"
)

// DestinationAzureBlobStorageUpdateOutputFormat - Format of the data output.
type DestinationAzureBlobStorageUpdateOutputFormat struct {
	DestinationAzureBlobStorageUpdateCSVCommaSeparatedValues       *DestinationAzureBlobStorageUpdateCSVCommaSeparatedValues       `queryParam:"inline"`
	DestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON *DestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON `queryParam:"inline"`

	Type DestinationAzureBlobStorageUpdateOutputFormatType
}

func CreateDestinationAzureBlobStorageUpdateOutputFormatDestinationAzureBlobStorageUpdateCSVCommaSeparatedValues(destinationAzureBlobStorageUpdateCSVCommaSeparatedValues DestinationAzureBlobStorageUpdateCSVCommaSeparatedValues) DestinationAzureBlobStorageUpdateOutputFormat {
	typ := DestinationAzureBlobStorageUpdateOutputFormatTypeDestinationAzureBlobStorageUpdateCSVCommaSeparatedValues

	return DestinationAzureBlobStorageUpdateOutputFormat{
		DestinationAzureBlobStorageUpdateCSVCommaSeparatedValues: &destinationAzureBlobStorageUpdateCSVCommaSeparatedValues,
		Type: typ,
	}
}

func CreateDestinationAzureBlobStorageUpdateOutputFormatDestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON(destinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON DestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON) DestinationAzureBlobStorageUpdateOutputFormat {
	typ := DestinationAzureBlobStorageUpdateOutputFormatTypeDestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON

	return DestinationAzureBlobStorageUpdateOutputFormat{
		DestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON: &destinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON,
		Type: typ,
	}
}

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

	var destinationAzureBlobStorageUpdateCSVCommaSeparatedValues DestinationAzureBlobStorageUpdateCSVCommaSeparatedValues = DestinationAzureBlobStorageUpdateCSVCommaSeparatedValues{}
	if err := utils.UnmarshalJSON(data, &destinationAzureBlobStorageUpdateCSVCommaSeparatedValues, "", true, true); err == nil {
		u.DestinationAzureBlobStorageUpdateCSVCommaSeparatedValues = &destinationAzureBlobStorageUpdateCSVCommaSeparatedValues
		u.Type = DestinationAzureBlobStorageUpdateOutputFormatTypeDestinationAzureBlobStorageUpdateCSVCommaSeparatedValues
		return nil
	}

	var destinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON DestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON = DestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON{}
	if err := utils.UnmarshalJSON(data, &destinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON, "", true, true); err == nil {
		u.DestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON = &destinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON
		u.Type = DestinationAzureBlobStorageUpdateOutputFormatTypeDestinationAzureBlobStorageUpdateJSONLinesNewlineDelimitedJSON
		return nil
	}

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

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

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

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

type DestinationAzureBlobStorageUpdate struct {
	// The Azure blob storage account key. If you set this value, you must not set the Shared Access Signature.
	AzureBlobStorageAccountKey *string `json:"azure_blob_storage_account_key,omitempty"`
	// The name of the Azure Blob Storage Account. Read more <a href="https://learn.microsoft.com/en-gb/azure/storage/blobs/storage-blobs-introduction#storage-accounts">here</a>.
	AzureBlobStorageAccountName string `json:"azure_blob_storage_account_name"`
	// The name of the Azure Blob Storage Container. Read more <a href="https://learn.microsoft.com/en-gb/azure/storage/blobs/storage-blobs-introduction#containers">here</a>.
	AzureBlobStorageContainerName string `json:"azure_blob_storage_container_name"`
	// This is Azure Blob Storage endpoint domain name. Leave default value (or leave it empty if run container from command line) to use Microsoft native from example.
	AzureBlobStorageEndpointDomainName *string `json:"azure_blob_storage_endpoint_domain_name,omitempty"`
	// The amount of megabytes after which the connector should spill the records in a new blob object. Make sure to configure size greater than individual records. Enter 0 if not applicable.
	AzureBlobStorageSpillSize *int64 `default:"500" json:"azure_blob_storage_spill_size"`
	// Format of the data output.
	Format DestinationAzureBlobStorageUpdateOutputFormat `json:"format"`
	// A shared access signature (SAS) provides secure delegated access to resources in your storage account. Read more <a href="https://learn.microsoft.com/en-gb/azure/storage/common/storage-sas-overview?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json&bc=%2Fazure%2Fstorage%2Fblobs%2Fbreadcrumb%2Ftoc.json">here</a>. If you set this value, you must not set the account key.
	SharedAccessSignature *string `json:"shared_access_signature,omitempty"`
}

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

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

func (o *DestinationAzureBlobStorageUpdate) GetAzureBlobStorageAccountKey() *string {
	if o == nil {
		return nil
	}
	return o.AzureBlobStorageAccountKey
}

func (o *DestinationAzureBlobStorageUpdate) GetAzureBlobStorageAccountName() string {
	if o == nil {
		return ""
	}
	return o.AzureBlobStorageAccountName
}

func (o *DestinationAzureBlobStorageUpdate) GetAzureBlobStorageContainerName() string {
	if o == nil {
		return ""
	}
	return o.AzureBlobStorageContainerName
}

func (o *DestinationAzureBlobStorageUpdate) GetAzureBlobStorageEndpointDomainName() *string {
	if o == nil {
		return nil
	}
	return o.AzureBlobStorageEndpointDomainName
}

func (o *DestinationAzureBlobStorageUpdate) GetAzureBlobStorageSpillSize() *int64 {
	if o == nil {
		return nil
	}
	return o.AzureBlobStorageSpillSize
}

func (o *DestinationAzureBlobStorageUpdate) GetFormat() DestinationAzureBlobStorageUpdateOutputFormat {
	if o == nil {
		return DestinationAzureBlobStorageUpdateOutputFormat{}
	}
	return o.Format
}

func (o *DestinationAzureBlobStorageUpdate) GetSharedAccessSignature() *string {
	if o == nil {
		return nil
	}
	return o.SharedAccessSignature
}
