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

const (
	SourceRetentlyUpdateSchemasAuthTypeToken SourceRetentlyUpdateSchemasAuthType = "Token"
)

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

type SourceRetentlyUpdateAuthenticateWithAPIToken struct {
	// Retently API Token. See the <a href="https://app.retently.com/settings/api/tokens">docs</a> for more information on how to obtain this key.
	APIKey               string                               `json:"api_key"`
	authType             *SourceRetentlyUpdateSchemasAuthType `const:"Token" json:"auth_type,omitempty"`
	AdditionalProperties any                                  `additionalProperties:"true" json:"-"`
}

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

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

func (o *SourceRetentlyUpdateAuthenticateWithAPIToken) GetAPIKey() string {
	if o == nil {
		return ""
	}
	return o.APIKey
}

func (o *SourceRetentlyUpdateAuthenticateWithAPIToken) GetAuthType() *SourceRetentlyUpdateSchemasAuthType {
	return SourceRetentlyUpdateSchemasAuthTypeToken.ToPointer()
}

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

type SourceRetentlyUpdateAuthType string

const (
	SourceRetentlyUpdateAuthTypeClient SourceRetentlyUpdateAuthType = "Client"
)

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

type SourceRetentlyUpdateAuthenticateViaRetentlyOAuth struct {
	authType *SourceRetentlyUpdateAuthType `const:"Client" json:"auth_type,omitempty"`
	// The Client ID of your Retently developer application.
	ClientID string `json:"client_id"`
	// The Client Secret of your Retently developer application.
	ClientSecret string `json:"client_secret"`
	// Retently Refresh Token which can be used to fetch new Bearer Tokens when the current one expires.
	RefreshToken         string `json:"refresh_token"`
	AdditionalProperties any    `additionalProperties:"true" json:"-"`
}

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

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

func (o *SourceRetentlyUpdateAuthenticateViaRetentlyOAuth) GetAuthType() *SourceRetentlyUpdateAuthType {
	return SourceRetentlyUpdateAuthTypeClient.ToPointer()
}

func (o *SourceRetentlyUpdateAuthenticateViaRetentlyOAuth) GetClientID() string {
	if o == nil {
		return ""
	}
	return o.ClientID
}

func (o *SourceRetentlyUpdateAuthenticateViaRetentlyOAuth) GetClientSecret() string {
	if o == nil {
		return ""
	}
	return o.ClientSecret
}

func (o *SourceRetentlyUpdateAuthenticateViaRetentlyOAuth) GetRefreshToken() string {
	if o == nil {
		return ""
	}
	return o.RefreshToken
}

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

type SourceRetentlyUpdateAuthenticationMechanismType string

const (
	SourceRetentlyUpdateAuthenticationMechanismTypeSourceRetentlyUpdateAuthenticateViaRetentlyOAuth SourceRetentlyUpdateAuthenticationMechanismType = "source-retently-update_Authenticate via Retently (OAuth)"
	SourceRetentlyUpdateAuthenticationMechanismTypeSourceRetentlyUpdateAuthenticateWithAPIToken     SourceRetentlyUpdateAuthenticationMechanismType = "source-retently-update_Authenticate with API Token"
)

// SourceRetentlyUpdateAuthenticationMechanism - Choose how to authenticate to Retently
type SourceRetentlyUpdateAuthenticationMechanism struct {
	SourceRetentlyUpdateAuthenticateViaRetentlyOAuth *SourceRetentlyUpdateAuthenticateViaRetentlyOAuth `queryParam:"inline"`
	SourceRetentlyUpdateAuthenticateWithAPIToken     *SourceRetentlyUpdateAuthenticateWithAPIToken     `queryParam:"inline"`

	Type SourceRetentlyUpdateAuthenticationMechanismType
}

func CreateSourceRetentlyUpdateAuthenticationMechanismSourceRetentlyUpdateAuthenticateViaRetentlyOAuth(sourceRetentlyUpdateAuthenticateViaRetentlyOAuth SourceRetentlyUpdateAuthenticateViaRetentlyOAuth) SourceRetentlyUpdateAuthenticationMechanism {
	typ := SourceRetentlyUpdateAuthenticationMechanismTypeSourceRetentlyUpdateAuthenticateViaRetentlyOAuth

	return SourceRetentlyUpdateAuthenticationMechanism{
		SourceRetentlyUpdateAuthenticateViaRetentlyOAuth: &sourceRetentlyUpdateAuthenticateViaRetentlyOAuth,
		Type: typ,
	}
}

func CreateSourceRetentlyUpdateAuthenticationMechanismSourceRetentlyUpdateAuthenticateWithAPIToken(sourceRetentlyUpdateAuthenticateWithAPIToken SourceRetentlyUpdateAuthenticateWithAPIToken) SourceRetentlyUpdateAuthenticationMechanism {
	typ := SourceRetentlyUpdateAuthenticationMechanismTypeSourceRetentlyUpdateAuthenticateWithAPIToken

	return SourceRetentlyUpdateAuthenticationMechanism{
		SourceRetentlyUpdateAuthenticateWithAPIToken: &sourceRetentlyUpdateAuthenticateWithAPIToken,
		Type: typ,
	}
}

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

	var sourceRetentlyUpdateAuthenticateWithAPIToken SourceRetentlyUpdateAuthenticateWithAPIToken = SourceRetentlyUpdateAuthenticateWithAPIToken{}
	if err := utils.UnmarshalJSON(data, &sourceRetentlyUpdateAuthenticateWithAPIToken, "", true, true); err == nil {
		u.SourceRetentlyUpdateAuthenticateWithAPIToken = &sourceRetentlyUpdateAuthenticateWithAPIToken
		u.Type = SourceRetentlyUpdateAuthenticationMechanismTypeSourceRetentlyUpdateAuthenticateWithAPIToken
		return nil
	}

	var sourceRetentlyUpdateAuthenticateViaRetentlyOAuth SourceRetentlyUpdateAuthenticateViaRetentlyOAuth = SourceRetentlyUpdateAuthenticateViaRetentlyOAuth{}
	if err := utils.UnmarshalJSON(data, &sourceRetentlyUpdateAuthenticateViaRetentlyOAuth, "", true, true); err == nil {
		u.SourceRetentlyUpdateAuthenticateViaRetentlyOAuth = &sourceRetentlyUpdateAuthenticateViaRetentlyOAuth
		u.Type = SourceRetentlyUpdateAuthenticationMechanismTypeSourceRetentlyUpdateAuthenticateViaRetentlyOAuth
		return nil
	}

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

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

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

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

type SourceRetentlyUpdate struct {
	// Choose how to authenticate to Retently
	Credentials *SourceRetentlyUpdateAuthenticationMechanism `json:"credentials,omitempty"`
}

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