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

const (
	SourceDynamodbSchemasAuthTypeRole SourceDynamodbSchemasAuthType = "Role"
)

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

type RoleBasedAuthentication struct {
	authType             *SourceDynamodbSchemasAuthType `const:"Role" json:"auth_type,omitempty"`
	AdditionalProperties any                            `additionalProperties:"true" json:"-"`
}

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

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

func (o *RoleBasedAuthentication) GetAuthType() *SourceDynamodbSchemasAuthType {
	return SourceDynamodbSchemasAuthTypeRole.ToPointer()
}

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

type SourceDynamodbAuthType string

const (
	SourceDynamodbAuthTypeUser SourceDynamodbAuthType = "User"
)

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

type AuthenticateViaAccessKeys struct {
	// The access key id to access Dynamodb. Airbyte requires read permissions to the database
	AccessKeyID string                  `json:"access_key_id"`
	authType    *SourceDynamodbAuthType `const:"User" json:"auth_type,omitempty"`
	// The corresponding secret to the access key id.
	SecretAccessKey      string `json:"secret_access_key"`
	AdditionalProperties any    `additionalProperties:"true" json:"-"`
}

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

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

func (o *AuthenticateViaAccessKeys) GetAccessKeyID() string {
	if o == nil {
		return ""
	}
	return o.AccessKeyID
}

func (o *AuthenticateViaAccessKeys) GetAuthType() *SourceDynamodbAuthType {
	return SourceDynamodbAuthTypeUser.ToPointer()
}

func (o *AuthenticateViaAccessKeys) GetSecretAccessKey() string {
	if o == nil {
		return ""
	}
	return o.SecretAccessKey
}

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

type CredentialsType string

const (
	CredentialsTypeAuthenticateViaAccessKeys CredentialsType = "Authenticate via Access Keys"
	CredentialsTypeRoleBasedAuthentication   CredentialsType = "Role Based Authentication"
)

// Credentials for the service
type Credentials struct {
	AuthenticateViaAccessKeys *AuthenticateViaAccessKeys `queryParam:"inline"`
	RoleBasedAuthentication   *RoleBasedAuthentication   `queryParam:"inline"`

	Type CredentialsType
}

func CreateCredentialsAuthenticateViaAccessKeys(authenticateViaAccessKeys AuthenticateViaAccessKeys) Credentials {
	typ := CredentialsTypeAuthenticateViaAccessKeys

	return Credentials{
		AuthenticateViaAccessKeys: &authenticateViaAccessKeys,
		Type:                      typ,
	}
}

func CreateCredentialsRoleBasedAuthentication(roleBasedAuthentication RoleBasedAuthentication) Credentials {
	typ := CredentialsTypeRoleBasedAuthentication

	return Credentials{
		RoleBasedAuthentication: &roleBasedAuthentication,
		Type:                    typ,
	}
}

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

	var roleBasedAuthentication RoleBasedAuthentication = RoleBasedAuthentication{}
	if err := utils.UnmarshalJSON(data, &roleBasedAuthentication, "", true, true); err == nil {
		u.RoleBasedAuthentication = &roleBasedAuthentication
		u.Type = CredentialsTypeRoleBasedAuthentication
		return nil
	}

	var authenticateViaAccessKeys AuthenticateViaAccessKeys = AuthenticateViaAccessKeys{}
	if err := utils.UnmarshalJSON(data, &authenticateViaAccessKeys, "", true, true); err == nil {
		u.AuthenticateViaAccessKeys = &authenticateViaAccessKeys
		u.Type = CredentialsTypeAuthenticateViaAccessKeys
		return nil
	}

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

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

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

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

// DynamodbRegion - The region of the Dynamodb database
type DynamodbRegion string

const (
	DynamodbRegionUnknown      DynamodbRegion = ""
	DynamodbRegionAfSouth1     DynamodbRegion = "af-south-1"
	DynamodbRegionApEast1      DynamodbRegion = "ap-east-1"
	DynamodbRegionApNortheast1 DynamodbRegion = "ap-northeast-1"
	DynamodbRegionApNortheast2 DynamodbRegion = "ap-northeast-2"
	DynamodbRegionApNortheast3 DynamodbRegion = "ap-northeast-3"
	DynamodbRegionApSouth1     DynamodbRegion = "ap-south-1"
	DynamodbRegionApSouth2     DynamodbRegion = "ap-south-2"
	DynamodbRegionApSoutheast1 DynamodbRegion = "ap-southeast-1"
	DynamodbRegionApSoutheast2 DynamodbRegion = "ap-southeast-2"
	DynamodbRegionApSoutheast3 DynamodbRegion = "ap-southeast-3"
	DynamodbRegionApSoutheast4 DynamodbRegion = "ap-southeast-4"
	DynamodbRegionCaCentral1   DynamodbRegion = "ca-central-1"
	DynamodbRegionCaWest1      DynamodbRegion = "ca-west-1"
	DynamodbRegionCnNorth1     DynamodbRegion = "cn-north-1"
	DynamodbRegionCnNorthwest1 DynamodbRegion = "cn-northwest-1"
	DynamodbRegionEuCentral1   DynamodbRegion = "eu-central-1"
	DynamodbRegionEuCentral2   DynamodbRegion = "eu-central-2"
	DynamodbRegionEuNorth1     DynamodbRegion = "eu-north-1"
	DynamodbRegionEuSouth1     DynamodbRegion = "eu-south-1"
	DynamodbRegionEuSouth2     DynamodbRegion = "eu-south-2"
	DynamodbRegionEuWest1      DynamodbRegion = "eu-west-1"
	DynamodbRegionEuWest2      DynamodbRegion = "eu-west-2"
	DynamodbRegionEuWest3      DynamodbRegion = "eu-west-3"
	DynamodbRegionIlCentral1   DynamodbRegion = "il-central-1"
	DynamodbRegionMeCentral1   DynamodbRegion = "me-central-1"
	DynamodbRegionMeSouth1     DynamodbRegion = "me-south-1"
	DynamodbRegionSaEast1      DynamodbRegion = "sa-east-1"
	DynamodbRegionUsEast1      DynamodbRegion = "us-east-1"
	DynamodbRegionUsEast2      DynamodbRegion = "us-east-2"
	DynamodbRegionUsGovEast1   DynamodbRegion = "us-gov-east-1"
	DynamodbRegionUsGovWest1   DynamodbRegion = "us-gov-west-1"
	DynamodbRegionUsWest1      DynamodbRegion = "us-west-1"
	DynamodbRegionUsWest2      DynamodbRegion = "us-west-2"
)

func (e DynamodbRegion) ToPointer() *DynamodbRegion {
	return &e
}
func (e *DynamodbRegion) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "":
		fallthrough
	case "af-south-1":
		fallthrough
	case "ap-east-1":
		fallthrough
	case "ap-northeast-1":
		fallthrough
	case "ap-northeast-2":
		fallthrough
	case "ap-northeast-3":
		fallthrough
	case "ap-south-1":
		fallthrough
	case "ap-south-2":
		fallthrough
	case "ap-southeast-1":
		fallthrough
	case "ap-southeast-2":
		fallthrough
	case "ap-southeast-3":
		fallthrough
	case "ap-southeast-4":
		fallthrough
	case "ca-central-1":
		fallthrough
	case "ca-west-1":
		fallthrough
	case "cn-north-1":
		fallthrough
	case "cn-northwest-1":
		fallthrough
	case "eu-central-1":
		fallthrough
	case "eu-central-2":
		fallthrough
	case "eu-north-1":
		fallthrough
	case "eu-south-1":
		fallthrough
	case "eu-south-2":
		fallthrough
	case "eu-west-1":
		fallthrough
	case "eu-west-2":
		fallthrough
	case "eu-west-3":
		fallthrough
	case "il-central-1":
		fallthrough
	case "me-central-1":
		fallthrough
	case "me-south-1":
		fallthrough
	case "sa-east-1":
		fallthrough
	case "us-east-1":
		fallthrough
	case "us-east-2":
		fallthrough
	case "us-gov-east-1":
		fallthrough
	case "us-gov-west-1":
		fallthrough
	case "us-west-1":
		fallthrough
	case "us-west-2":
		*e = DynamodbRegion(v)
		return nil
	default:
		return fmt.Errorf("invalid value for DynamodbRegion: %v", v)
	}
}

type Dynamodb string

const (
	DynamodbDynamodb Dynamodb = "dynamodb"
)

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

type SourceDynamodb struct {
	// Credentials for the service
	Credentials *Credentials `json:"credentials,omitempty"`
	// the URL of the Dynamodb database
	Endpoint *string `default:"" json:"endpoint"`
	// Ignore tables with missing scan/read permissions
	IgnoreMissingReadPermissionsTables *bool `default:"false" json:"ignore_missing_read_permissions_tables"`
	// The region of the Dynamodb database
	Region *DynamodbRegion `default:"" json:"region"`
	// Comma separated reserved attribute names present in your tables
	ReservedAttributeNames *string   `json:"reserved_attribute_names,omitempty"`
	sourceType             *Dynamodb `const:"dynamodb" json:"sourceType,omitempty"`
}

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

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

func (o *SourceDynamodb) GetCredentials() *Credentials {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceDynamodb) GetEndpoint() *string {
	if o == nil {
		return nil
	}
	return o.Endpoint
}

func (o *SourceDynamodb) GetIgnoreMissingReadPermissionsTables() *bool {
	if o == nil {
		return nil
	}
	return o.IgnoreMissingReadPermissionsTables
}

func (o *SourceDynamodb) GetRegion() *DynamodbRegion {
	if o == nil {
		return nil
	}
	return o.Region
}

func (o *SourceDynamodb) GetReservedAttributeNames() *string {
	if o == nil {
		return nil
	}
	return o.ReservedAttributeNames
}

func (o *SourceDynamodb) GetSourceType() *Dynamodb {
	return DynamodbDynamodb.ToPointer()
}
