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

const (
	SourceFaunaDeletionModeDeletedField SourceFaunaDeletionMode = "deleted_field"
)

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

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

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

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

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

func (o *Enabled) GetDeletionMode() SourceFaunaDeletionMode {
	return SourceFaunaDeletionModeDeletedField
}

type SourceFaunaSchemasDeletionMode string

const (
	SourceFaunaSchemasDeletionModeIgnore SourceFaunaSchemasDeletionMode = "ignore"
)

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

type Disabled struct {
	deletionMode SourceFaunaSchemasDeletionMode `const:"ignore" json:"deletion_mode"`
}

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

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

func (o *Disabled) GetDeletionMode() SourceFaunaSchemasDeletionMode {
	return SourceFaunaSchemasDeletionModeIgnore
}

type DeletionModeType string

const (
	DeletionModeTypeDisabled DeletionModeType = "Disabled"
	DeletionModeTypeEnabled  DeletionModeType = "Enabled"
)

// DeletionMode - <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 DeletionMode struct {
	Disabled *Disabled `queryParam:"inline"`
	Enabled  *Enabled  `queryParam:"inline"`

	Type DeletionModeType
}

func CreateDeletionModeDisabled(disabled Disabled) DeletionMode {
	typ := DeletionModeTypeDisabled

	return DeletionMode{
		Disabled: &disabled,
		Type:     typ,
	}
}

func CreateDeletionModeEnabled(enabled Enabled) DeletionMode {
	typ := DeletionModeTypeEnabled

	return DeletionMode{
		Enabled: &enabled,
		Type:    typ,
	}
}

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

	var disabled Disabled = Disabled{}
	if err := utils.UnmarshalJSON(data, &disabled, "", true, true); err == nil {
		u.Disabled = &disabled
		u.Type = DeletionModeTypeDisabled
		return nil
	}

	var enabled Enabled = Enabled{}
	if err := utils.UnmarshalJSON(data, &enabled, "", true, true); err == nil {
		u.Enabled = &enabled
		u.Type = DeletionModeTypeEnabled
		return nil
	}

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

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

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

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

// Collection - Settings for the Fauna Collection.
type Collection 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 DeletionMode `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 (c Collection) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(c, "", false)
}

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

func (o *Collection) GetDeletions() DeletionMode {
	if o == nil {
		return DeletionMode{}
	}
	return o.Deletions
}

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

type Fauna string

const (
	FaunaFauna Fauna = "fauna"
)

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

type SourceFauna struct {
	// Settings for the Fauna Collection.
	Collection *Collection `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"`
	sourceType Fauna  `const:"fauna" json:"sourceType"`
}

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

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

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

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

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

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

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

func (o *SourceFauna) GetSourceType() Fauna {
	return FaunaFauna
}
