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

const (
	SourceSalesloftSchemasAuthTypeAPIKey SourceSalesloftSchemasAuthType = "api_key"
)

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

type AuthenticateViaAPIKey struct {
	// API Key for making authenticated requests. More instruction on how to find this value in our <a href="https://docs.airbyte.com/integrations/sources/salesloft#setup-guide">docs</a>
	APIKey   string                         `json:"api_key"`
	authType SourceSalesloftSchemasAuthType `const:"api_key" json:"auth_type"`
}

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

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

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

func (o *AuthenticateViaAPIKey) GetAuthType() SourceSalesloftSchemasAuthType {
	return SourceSalesloftSchemasAuthTypeAPIKey
}

type SourceSalesloftAuthType string

const (
	SourceSalesloftAuthTypeOauth20 SourceSalesloftAuthType = "oauth2.0"
)

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

type AuthenticateViaOAuth struct {
	// Access Token for making authenticated requests.
	AccessToken string                  `json:"access_token"`
	authType    SourceSalesloftAuthType `const:"oauth2.0" json:"auth_type"`
	// The Client ID of your Salesloft developer application.
	ClientID string `json:"client_id"`
	// The Client Secret of your Salesloft developer application.
	ClientSecret string `json:"client_secret"`
	// The token for obtaining a new 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 (a AuthenticateViaOAuth) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(a, "", false)
}

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

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

func (o *AuthenticateViaOAuth) GetAuthType() SourceSalesloftAuthType {
	return SourceSalesloftAuthTypeOauth20
}

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

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

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

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

type SourceSalesloftCredentialsType string

const (
	SourceSalesloftCredentialsTypeAuthenticateViaOAuth  SourceSalesloftCredentialsType = "Authenticate via OAuth"
	SourceSalesloftCredentialsTypeAuthenticateViaAPIKey SourceSalesloftCredentialsType = "Authenticate via API Key"
)

type SourceSalesloftCredentials struct {
	AuthenticateViaOAuth  *AuthenticateViaOAuth  `queryParam:"inline"`
	AuthenticateViaAPIKey *AuthenticateViaAPIKey `queryParam:"inline"`

	Type SourceSalesloftCredentialsType
}

func CreateSourceSalesloftCredentialsAuthenticateViaOAuth(authenticateViaOAuth AuthenticateViaOAuth) SourceSalesloftCredentials {
	typ := SourceSalesloftCredentialsTypeAuthenticateViaOAuth

	return SourceSalesloftCredentials{
		AuthenticateViaOAuth: &authenticateViaOAuth,
		Type:                 typ,
	}
}

func CreateSourceSalesloftCredentialsAuthenticateViaAPIKey(authenticateViaAPIKey AuthenticateViaAPIKey) SourceSalesloftCredentials {
	typ := SourceSalesloftCredentialsTypeAuthenticateViaAPIKey

	return SourceSalesloftCredentials{
		AuthenticateViaAPIKey: &authenticateViaAPIKey,
		Type:                  typ,
	}
}

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

	var authenticateViaAPIKey AuthenticateViaAPIKey = AuthenticateViaAPIKey{}
	if err := utils.UnmarshalJSON(data, &authenticateViaAPIKey, "", true, true); err == nil {
		u.AuthenticateViaAPIKey = &authenticateViaAPIKey
		u.Type = SourceSalesloftCredentialsTypeAuthenticateViaAPIKey
		return nil
	}

	var authenticateViaOAuth AuthenticateViaOAuth = AuthenticateViaOAuth{}
	if err := utils.UnmarshalJSON(data, &authenticateViaOAuth, "", true, true); err == nil {
		u.AuthenticateViaOAuth = &authenticateViaOAuth
		u.Type = SourceSalesloftCredentialsTypeAuthenticateViaOAuth
		return nil
	}

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

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

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

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

type Salesloft string

const (
	SalesloftSalesloft Salesloft = "salesloft"
)

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

type SourceSalesloft struct {
	Credentials SourceSalesloftCredentials `json:"credentials"`
	// The date from which you'd like to replicate data for Salesloft API, in the format YYYY-MM-DDT00:00:00Z. All data generated after this date will be replicated.
	StartDate  time.Time `json:"start_date"`
	sourceType Salesloft `const:"salesloft" json:"sourceType"`
}

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

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

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

func (o *SourceSalesloft) GetStartDate() time.Time {
	if o == nil {
		return time.Time{}
	}
	return o.StartDate
}

func (o *SourceSalesloft) GetSourceType() Salesloft {
	return SalesloftSalesloft
}
