// 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"
	"time"
)

type SourceTrustpilotSchemasAuthType string

const (
	SourceTrustpilotSchemasAuthTypeApikey SourceTrustpilotSchemasAuthType = "apikey"
)

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

// SourceTrustpilotAPIKey - The API key authentication method gives you access to only the streams which are part of the Public API. When you want to get streams available via the Consumer API (e.g. the private reviews) you need to use authentication method OAuth 2.0.
type SourceTrustpilotAPIKey struct {
	authType *SourceTrustpilotSchemasAuthType `const:"apikey" json:"auth_type,omitempty"`
	// The API key of the Trustpilot API application.
	ClientID string `json:"client_id"`
}

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

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

func (o *SourceTrustpilotAPIKey) GetAuthType() *SourceTrustpilotSchemasAuthType {
	return SourceTrustpilotSchemasAuthTypeApikey.ToPointer()
}

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

type SourceTrustpilotAuthType string

const (
	SourceTrustpilotAuthTypeOauth20 SourceTrustpilotAuthType = "oauth2.0"
)

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

type SourceTrustpilotOAuth20 struct {
	// Access Token for making authenticated requests.
	AccessToken string                    `json:"access_token"`
	authType    *SourceTrustpilotAuthType `const:"oauth2.0" json:"auth_type,omitempty"`
	// The API key of the Trustpilot API application. (represents the OAuth Client ID)
	ClientID string `json:"client_id"`
	// The Secret of the Trustpilot API application. (represents the OAuth Client Secret)
	ClientSecret string `json:"client_secret"`
	// The key to refresh the expired access_token.
	RefreshToken string `json:"refresh_token"`
	// The date-time when the access token should be refreshed.
	TokenExpiryDate time.Time `json:"token_expiry_date"`
}

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

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

func (o *SourceTrustpilotOAuth20) GetAccessToken() string {
	if o == nil {
		return ""
	}
	return o.AccessToken
}

func (o *SourceTrustpilotOAuth20) GetAuthType() *SourceTrustpilotAuthType {
	return SourceTrustpilotAuthTypeOauth20.ToPointer()
}

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

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

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

func (o *SourceTrustpilotOAuth20) GetTokenExpiryDate() time.Time {
	if o == nil {
		return time.Time{}
	}
	return o.TokenExpiryDate
}

type SourceTrustpilotAuthorizationMethodType string

const (
	SourceTrustpilotAuthorizationMethodTypeSourceTrustpilotOAuth20 SourceTrustpilotAuthorizationMethodType = "source-trustpilot_OAuth 2.0"
	SourceTrustpilotAuthorizationMethodTypeSourceTrustpilotAPIKey  SourceTrustpilotAuthorizationMethodType = "source-trustpilot_API Key"
)

type SourceTrustpilotAuthorizationMethod struct {
	SourceTrustpilotOAuth20 *SourceTrustpilotOAuth20 `queryParam:"inline"`
	SourceTrustpilotAPIKey  *SourceTrustpilotAPIKey  `queryParam:"inline"`

	Type SourceTrustpilotAuthorizationMethodType
}

func CreateSourceTrustpilotAuthorizationMethodSourceTrustpilotOAuth20(sourceTrustpilotOAuth20 SourceTrustpilotOAuth20) SourceTrustpilotAuthorizationMethod {
	typ := SourceTrustpilotAuthorizationMethodTypeSourceTrustpilotOAuth20

	return SourceTrustpilotAuthorizationMethod{
		SourceTrustpilotOAuth20: &sourceTrustpilotOAuth20,
		Type:                    typ,
	}
}

func CreateSourceTrustpilotAuthorizationMethodSourceTrustpilotAPIKey(sourceTrustpilotAPIKey SourceTrustpilotAPIKey) SourceTrustpilotAuthorizationMethod {
	typ := SourceTrustpilotAuthorizationMethodTypeSourceTrustpilotAPIKey

	return SourceTrustpilotAuthorizationMethod{
		SourceTrustpilotAPIKey: &sourceTrustpilotAPIKey,
		Type:                   typ,
	}
}

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

	var sourceTrustpilotAPIKey SourceTrustpilotAPIKey = SourceTrustpilotAPIKey{}
	if err := utils.UnmarshalJSON(data, &sourceTrustpilotAPIKey, "", true, true); err == nil {
		u.SourceTrustpilotAPIKey = &sourceTrustpilotAPIKey
		u.Type = SourceTrustpilotAuthorizationMethodTypeSourceTrustpilotAPIKey
		return nil
	}

	var sourceTrustpilotOAuth20 SourceTrustpilotOAuth20 = SourceTrustpilotOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceTrustpilotOAuth20, "", true, true); err == nil {
		u.SourceTrustpilotOAuth20 = &sourceTrustpilotOAuth20
		u.Type = SourceTrustpilotAuthorizationMethodTypeSourceTrustpilotOAuth20
		return nil
	}

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

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

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

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

type Trustpilot string

const (
	TrustpilotTrustpilot Trustpilot = "trustpilot"
)

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

type SourceTrustpilot struct {
	// The names of business units which shall be synchronized. Some streams e.g. configured_business_units or private_reviews use this configuration.
	BusinessUnits []string                            `json:"business_units"`
	Credentials   SourceTrustpilotAuthorizationMethod `json:"credentials"`
	// For streams with sync. method incremental the start date time to be used
	StartDate  string     `json:"start_date"`
	sourceType Trustpilot `const:"trustpilot" json:"sourceType"`
}

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

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

func (o *SourceTrustpilot) GetBusinessUnits() []string {
	if o == nil {
		return []string{}
	}
	return o.BusinessUnits
}

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

func (o *SourceTrustpilot) GetStartDate() string {
	if o == nil {
		return ""
	}
	return o.StartDate
}

func (o *SourceTrustpilot) GetSourceType() Trustpilot {
	return TrustpilotTrustpilot
}
