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

const (
	SourceFaunaUpdateSchemasDeletionModeDeletedField SourceFaunaUpdateSchemasDeletionMode = "deleted_field"
)

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

type SourceFaunaUpdateEnabled struct {
	// Name of the "deleted at" column.
	Column       *string                              `default:"deleted_at" json:"column"`
	deletionMode SourceFaunaUpdateSchemasDeletionMode `const:"deleted_field" json:"deletion_mode"`
}

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

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

func (o *SourceFaunaUpdateEnabled) GetColumn() *string {
	if o == nil {
		return nil
	}
	return o.Column
}

func (o *SourceFaunaUpdateEnabled) GetDeletionMode() SourceFaunaUpdateSchemasDeletionMode {
	return SourceFaunaUpdateSchemasDeletionModeDeletedField
}

type SourceFaunaUpdateSchemasCollectionDeletionMode string

const (
	SourceFaunaUpdateSchemasCollectionDeletionModeIgnore SourceFaunaUpdateSchemasCollectionDeletionMode = "ignore"
)

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

type SourceFaunaUpdateDisabled struct {
	deletionMode SourceFaunaUpdateSchemasCollectionDeletionMode `const:"ignore" json:"deletion_mode"`
}

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

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

func (o *SourceFaunaUpdateDisabled) GetDeletionMode() SourceFaunaUpdateSchemasCollectionDeletionMode {
	return SourceFaunaUpdateSchemasCollectionDeletionModeIgnore
}

type SourceFaunaUpdateDeletionModeType string

const (
	SourceFaunaUpdateDeletionModeTypeSourceFaunaUpdateDisabled SourceFaunaUpdateDeletionModeType = "source-fauna-update_Disabled"
	SourceFaunaUpdateDeletionModeTypeSourceFaunaUpdateEnabled  SourceFaunaUpdateDeletionModeType = "source-fauna-update_Enabled"
)

// SourceFaunaUpdateDeletionMode - <b>This only applies to incremental syncs.</b> <br>
// Enabling deletion mode informs your destination of deleted documents.<br>
// Disabled - Leave this feature disabled, and ignore deleted documents.<br>
// Enabled - Enables this feature. When a document is deleted, the connector exports a record with a "deleted at" column containing the time that the document was deleted.
type SourceFaunaUpdateDeletionMode struct {
	SourceFaunaUpdateDisabled *SourceFaunaUpdateDisabled `queryParam:"inline"`
	SourceFaunaUpdateEnabled  *SourceFaunaUpdateEnabled  `queryParam:"inline"`

	Type SourceFaunaUpdateDeletionModeType
}

func CreateSourceFaunaUpdateDeletionModeSourceFaunaUpdateDisabled(sourceFaunaUpdateDisabled SourceFaunaUpdateDisabled) SourceFaunaUpdateDeletionMode {
	typ := SourceFaunaUpdateDeletionModeTypeSourceFaunaUpdateDisabled

	return SourceFaunaUpdateDeletionMode{
		SourceFaunaUpdateDisabled: &sourceFaunaUpdateDisabled,
		Type:                      typ,
	}
}

func CreateSourceFaunaUpdateDeletionModeSourceFaunaUpdateEnabled(sourceFaunaUpdateEnabled SourceFaunaUpdateEnabled) SourceFaunaUpdateDeletionMode {
	typ := SourceFaunaUpdateDeletionModeTypeSourceFaunaUpdateEnabled

	return SourceFaunaUpdateDeletionMode{
		SourceFaunaUpdateEnabled: &sourceFaunaUpdateEnabled,
		Type:                     typ,
	}
}

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

	var sourceFaunaUpdateDisabled SourceFaunaUpdateDisabled = SourceFaunaUpdateDisabled{}
	if err := utils.UnmarshalJSON(data, &sourceFaunaUpdateDisabled, "", true, true); err == nil {
		u.SourceFaunaUpdateDisabled = &sourceFaunaUpdateDisabled
		u.Type = SourceFaunaUpdateDeletionModeTypeSourceFaunaUpdateDisabled
		return nil
	}

	var sourceFaunaUpdateEnabled SourceFaunaUpdateEnabled = SourceFaunaUpdateEnabled{}
	if err := utils.UnmarshalJSON(data, &sourceFaunaUpdateEnabled, "", true, true); err == nil {
		u.SourceFaunaUpdateEnabled = &sourceFaunaUpdateEnabled
		u.Type = SourceFaunaUpdateDeletionModeTypeSourceFaunaUpdateEnabled
		return nil
	}

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

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

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

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

// SourceFaunaUpdateCollection - Settings for the Fauna Collection.
type SourceFaunaUpdateCollection struct {
	// <b>This only applies to incremental syncs.</b> <br>
	// Enabling deletion mode informs your destination of deleted documents.<br>
	// Disabled - Leave this feature disabled, and ignore deleted documents.<br>
	// Enabled - Enables this feature. When a document is deleted, the connector exports a record with a "deleted at" column containing the time that the document was deleted.
	Deletions SourceFaunaUpdateDeletionMode `json:"deletions"`
	// The page size used when reading documents from the database. The larger the page size, the faster the connector processes documents. However, if a page is too large, the connector may fail. <br>
	// Choose your page size based on how large the documents are. <br>
	// See <a href="https://docs.fauna.com/fauna/current/learn/understanding/types#page">the docs</a>.
	PageSize *int64 `default:"64" json:"page_size"`
}

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

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

func (o *SourceFaunaUpdateCollection) GetDeletions() SourceFaunaUpdateDeletionMode {
	if o == nil {
		return SourceFaunaUpdateDeletionMode{}
	}
	return o.Deletions
}

func (o *SourceFaunaUpdateCollection) GetPageSize() *int64 {
	if o == nil {
		return nil
	}
	return o.PageSize
}

type SourceFaunaUpdate struct {
	// Settings for the Fauna Collection.
	Collection *SourceFaunaUpdateCollection `json:"collection,omitempty"`
	// Domain of Fauna to query. Defaults db.fauna.com. See <a href=https://docs.fauna.com/fauna/current/learn/understanding/region_groups#how-to-use-region-groups>the docs</a>.
	Domain *string `default:"db.fauna.com" json:"domain"`
	// Endpoint port.
	Port *int64 `default:"443" json:"port"`
	// URL scheme.
	Scheme *string `default:"https" json:"scheme"`
	// Fauna secret, used when authenticating with the database.
	Secret string `json:"secret"`
}

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

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

func (o *SourceFaunaUpdate) GetCollection() *SourceFaunaUpdateCollection {
	if o == nil {
		return nil
	}
	return o.Collection
}

func (o *SourceFaunaUpdate) GetDomain() *string {
	if o == nil {
		return nil
	}
	return o.Domain
}

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

func (o *SourceFaunaUpdate) GetScheme() *string {
	if o == nil {
		return nil
	}
	return o.Scheme
}

func (o *SourceFaunaUpdate) GetSecret() string {
	if o == nil {
		return ""
	}
	return o.Secret
}
