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

const (
	SourceTrustpilotUpdateSchemasAuthTypeApikey SourceTrustpilotUpdateSchemasAuthType = "apikey"
)

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

// SourceTrustpilotUpdateAPIKey - 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 SourceTrustpilotUpdateAPIKey struct {
	authType *SourceTrustpilotUpdateSchemasAuthType `const:"apikey" json:"auth_type,omitempty"`
	// The API key of the Trustpilot API application.
	ClientID string `json:"client_id"`
}

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

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

func (o *SourceTrustpilotUpdateAPIKey) GetAuthType() *SourceTrustpilotUpdateSchemasAuthType {
	return SourceTrustpilotUpdateSchemasAuthTypeApikey.ToPointer()
}

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

type SourceTrustpilotUpdateAuthType string

const (
	SourceTrustpilotUpdateAuthTypeOauth20 SourceTrustpilotUpdateAuthType = "oauth2.0"
)

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

type SourceTrustpilotUpdateOAuth20 struct {
	// Access Token for making authenticated requests.
	AccessToken string                          `json:"access_token"`
	authType    *SourceTrustpilotUpdateAuthType `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 SourceTrustpilotUpdateOAuth20) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(s, "", false)
}

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

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

func (o *SourceTrustpilotUpdateOAuth20) GetAuthType() *SourceTrustpilotUpdateAuthType {
	return SourceTrustpilotUpdateAuthTypeOauth20.ToPointer()
}

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

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

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

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

type SourceTrustpilotUpdateAuthorizationMethodType string

const (
	SourceTrustpilotUpdateAuthorizationMethodTypeSourceTrustpilotUpdateOAuth20 SourceTrustpilotUpdateAuthorizationMethodType = "source-trustpilot-update_OAuth 2.0"
	SourceTrustpilotUpdateAuthorizationMethodTypeSourceTrustpilotUpdateAPIKey  SourceTrustpilotUpdateAuthorizationMethodType = "source-trustpilot-update_API Key"
)

type SourceTrustpilotUpdateAuthorizationMethod struct {
	SourceTrustpilotUpdateOAuth20 *SourceTrustpilotUpdateOAuth20 `queryParam:"inline"`
	SourceTrustpilotUpdateAPIKey  *SourceTrustpilotUpdateAPIKey  `queryParam:"inline"`

	Type SourceTrustpilotUpdateAuthorizationMethodType
}

func CreateSourceTrustpilotUpdateAuthorizationMethodSourceTrustpilotUpdateOAuth20(sourceTrustpilotUpdateOAuth20 SourceTrustpilotUpdateOAuth20) SourceTrustpilotUpdateAuthorizationMethod {
	typ := SourceTrustpilotUpdateAuthorizationMethodTypeSourceTrustpilotUpdateOAuth20

	return SourceTrustpilotUpdateAuthorizationMethod{
		SourceTrustpilotUpdateOAuth20: &sourceTrustpilotUpdateOAuth20,
		Type:                          typ,
	}
}

func CreateSourceTrustpilotUpdateAuthorizationMethodSourceTrustpilotUpdateAPIKey(sourceTrustpilotUpdateAPIKey SourceTrustpilotUpdateAPIKey) SourceTrustpilotUpdateAuthorizationMethod {
	typ := SourceTrustpilotUpdateAuthorizationMethodTypeSourceTrustpilotUpdateAPIKey

	return SourceTrustpilotUpdateAuthorizationMethod{
		SourceTrustpilotUpdateAPIKey: &sourceTrustpilotUpdateAPIKey,
		Type:                         typ,
	}
}

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

	var sourceTrustpilotUpdateAPIKey SourceTrustpilotUpdateAPIKey = SourceTrustpilotUpdateAPIKey{}
	if err := utils.UnmarshalJSON(data, &sourceTrustpilotUpdateAPIKey, "", true, true); err == nil {
		u.SourceTrustpilotUpdateAPIKey = &sourceTrustpilotUpdateAPIKey
		u.Type = SourceTrustpilotUpdateAuthorizationMethodTypeSourceTrustpilotUpdateAPIKey
		return nil
	}

	var sourceTrustpilotUpdateOAuth20 SourceTrustpilotUpdateOAuth20 = SourceTrustpilotUpdateOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceTrustpilotUpdateOAuth20, "", true, true); err == nil {
		u.SourceTrustpilotUpdateOAuth20 = &sourceTrustpilotUpdateOAuth20
		u.Type = SourceTrustpilotUpdateAuthorizationMethodTypeSourceTrustpilotUpdateOAuth20
		return nil
	}

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

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

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

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

type SourceTrustpilotUpdate 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   SourceTrustpilotUpdateAuthorizationMethod `json:"credentials"`
	// For streams with sync. method incremental the start date time to be used
	StartDate string `json:"start_date"`
}

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

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

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