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

const (
	SourceSalesloftUpdateSchemasAuthTypeAPIKey SourceSalesloftUpdateSchemasAuthType = "api_key"
)

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

type SourceSalesloftUpdateAuthenticateViaAPIKey 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 SourceSalesloftUpdateSchemasAuthType `const:"api_key" json:"auth_type"`
}

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

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

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

func (o *SourceSalesloftUpdateAuthenticateViaAPIKey) GetAuthType() SourceSalesloftUpdateSchemasAuthType {
	return SourceSalesloftUpdateSchemasAuthTypeAPIKey
}

type SourceSalesloftUpdateAuthType string

const (
	SourceSalesloftUpdateAuthTypeOauth20 SourceSalesloftUpdateAuthType = "oauth2.0"
)

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

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

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

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

func (o *SourceSalesloftUpdateAuthenticateViaOAuth) GetAuthType() SourceSalesloftUpdateAuthType {
	return SourceSalesloftUpdateAuthTypeOauth20
}

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

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

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

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

type SourceSalesloftUpdateCredentialsType string

const (
	SourceSalesloftUpdateCredentialsTypeSourceSalesloftUpdateAuthenticateViaOAuth  SourceSalesloftUpdateCredentialsType = "source-salesloft-update_Authenticate via OAuth"
	SourceSalesloftUpdateCredentialsTypeSourceSalesloftUpdateAuthenticateViaAPIKey SourceSalesloftUpdateCredentialsType = "source-salesloft-update_Authenticate via API Key"
)

type SourceSalesloftUpdateCredentials struct {
	SourceSalesloftUpdateAuthenticateViaOAuth  *SourceSalesloftUpdateAuthenticateViaOAuth  `queryParam:"inline"`
	SourceSalesloftUpdateAuthenticateViaAPIKey *SourceSalesloftUpdateAuthenticateViaAPIKey `queryParam:"inline"`

	Type SourceSalesloftUpdateCredentialsType
}

func CreateSourceSalesloftUpdateCredentialsSourceSalesloftUpdateAuthenticateViaOAuth(sourceSalesloftUpdateAuthenticateViaOAuth SourceSalesloftUpdateAuthenticateViaOAuth) SourceSalesloftUpdateCredentials {
	typ := SourceSalesloftUpdateCredentialsTypeSourceSalesloftUpdateAuthenticateViaOAuth

	return SourceSalesloftUpdateCredentials{
		SourceSalesloftUpdateAuthenticateViaOAuth: &sourceSalesloftUpdateAuthenticateViaOAuth,
		Type: typ,
	}
}

func CreateSourceSalesloftUpdateCredentialsSourceSalesloftUpdateAuthenticateViaAPIKey(sourceSalesloftUpdateAuthenticateViaAPIKey SourceSalesloftUpdateAuthenticateViaAPIKey) SourceSalesloftUpdateCredentials {
	typ := SourceSalesloftUpdateCredentialsTypeSourceSalesloftUpdateAuthenticateViaAPIKey

	return SourceSalesloftUpdateCredentials{
		SourceSalesloftUpdateAuthenticateViaAPIKey: &sourceSalesloftUpdateAuthenticateViaAPIKey,
		Type: typ,
	}
}

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

	var sourceSalesloftUpdateAuthenticateViaAPIKey SourceSalesloftUpdateAuthenticateViaAPIKey = SourceSalesloftUpdateAuthenticateViaAPIKey{}
	if err := utils.UnmarshalJSON(data, &sourceSalesloftUpdateAuthenticateViaAPIKey, "", true, true); err == nil {
		u.SourceSalesloftUpdateAuthenticateViaAPIKey = &sourceSalesloftUpdateAuthenticateViaAPIKey
		u.Type = SourceSalesloftUpdateCredentialsTypeSourceSalesloftUpdateAuthenticateViaAPIKey
		return nil
	}

	var sourceSalesloftUpdateAuthenticateViaOAuth SourceSalesloftUpdateAuthenticateViaOAuth = SourceSalesloftUpdateAuthenticateViaOAuth{}
	if err := utils.UnmarshalJSON(data, &sourceSalesloftUpdateAuthenticateViaOAuth, "", true, true); err == nil {
		u.SourceSalesloftUpdateAuthenticateViaOAuth = &sourceSalesloftUpdateAuthenticateViaOAuth
		u.Type = SourceSalesloftUpdateCredentialsTypeSourceSalesloftUpdateAuthenticateViaOAuth
		return nil
	}

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

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

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

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

type SourceSalesloftUpdate struct {
	Credentials SourceSalesloftUpdateCredentials `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"`
}

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

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

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

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