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

const (
	SourceZendeskSupportSchemasCredentialsAPIToken SourceZendeskSupportSchemasCredentials = "api_token"
)

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

type SourceZendeskSupportAPIToken struct {
	// The value of the API token generated. See our <a href="https://docs.airbyte.com/integrations/sources/zendesk-support#setup-guide">full documentation</a> for more information on generating this token.
	APIToken    string                                  `json:"api_token"`
	credentials *SourceZendeskSupportSchemasCredentials `const:"api_token" json:"credentials,omitempty"`
	// The user email for your Zendesk account.
	Email                string `json:"email"`
	AdditionalProperties any    `additionalProperties:"true" json:"-"`
}

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

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

func (o *SourceZendeskSupportAPIToken) GetAPIToken() string {
	if o == nil {
		return ""
	}
	return o.APIToken
}

func (o *SourceZendeskSupportAPIToken) GetCredentials() *SourceZendeskSupportSchemasCredentials {
	return SourceZendeskSupportSchemasCredentialsAPIToken.ToPointer()
}

func (o *SourceZendeskSupportAPIToken) GetEmail() string {
	if o == nil {
		return ""
	}
	return o.Email
}

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

type SourceZendeskSupportCredentials string

const (
	SourceZendeskSupportCredentialsOauth20 SourceZendeskSupportCredentials = "oauth2.0"
)

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

type SourceZendeskSupportOAuth20 struct {
	// The OAuth access token. See the <a href="https://developer.zendesk.com/documentation/ticketing/working-with-oauth/creating-and-using-oauth-tokens-with-the-api/">Zendesk docs</a> for more information on generating this token.
	AccessToken string `json:"access_token"`
	// The OAuth client's ID. See <a href="https://docs.searchunify.com/Content/Content-Sources/Zendesk-Authentication-OAuth-Client-ID-Secret.htm#:~:text=Get%20Client%20ID%20and%20Client%20Secret&text=Go%20to%20OAuth%20Clients%20and,will%20be%20displayed%20only%20once.">this guide</a> for more information.
	ClientID *string `json:"client_id,omitempty"`
	// The OAuth client secret. See <a href="https://docs.searchunify.com/Content/Content-Sources/Zendesk-Authentication-OAuth-Client-ID-Secret.htm#:~:text=Get%20Client%20ID%20and%20Client%20Secret&text=Go%20to%20OAuth%20Clients%20and,will%20be%20displayed%20only%20once.">this guide</a> for more information.
	ClientSecret         *string                          `json:"client_secret,omitempty"`
	credentials          *SourceZendeskSupportCredentials `const:"oauth2.0" json:"credentials,omitempty"`
	AdditionalProperties any                              `additionalProperties:"true" json:"-"`
}

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

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

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

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

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

func (o *SourceZendeskSupportOAuth20) GetCredentials() *SourceZendeskSupportCredentials {
	return SourceZendeskSupportCredentialsOauth20.ToPointer()
}

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

type SourceZendeskSupportAuthenticationType string

const (
	SourceZendeskSupportAuthenticationTypeSourceZendeskSupportOAuth20  SourceZendeskSupportAuthenticationType = "source-zendesk-support_OAuth2.0"
	SourceZendeskSupportAuthenticationTypeSourceZendeskSupportAPIToken SourceZendeskSupportAuthenticationType = "source-zendesk-support_API Token"
)

// SourceZendeskSupportAuthentication - Zendesk allows two authentication methods. We recommend using `OAuth2.0` for Airbyte Cloud users and `API token` for Airbyte Open Source users.
type SourceZendeskSupportAuthentication struct {
	SourceZendeskSupportOAuth20  *SourceZendeskSupportOAuth20  `queryParam:"inline"`
	SourceZendeskSupportAPIToken *SourceZendeskSupportAPIToken `queryParam:"inline"`

	Type SourceZendeskSupportAuthenticationType
}

func CreateSourceZendeskSupportAuthenticationSourceZendeskSupportOAuth20(sourceZendeskSupportOAuth20 SourceZendeskSupportOAuth20) SourceZendeskSupportAuthentication {
	typ := SourceZendeskSupportAuthenticationTypeSourceZendeskSupportOAuth20

	return SourceZendeskSupportAuthentication{
		SourceZendeskSupportOAuth20: &sourceZendeskSupportOAuth20,
		Type:                        typ,
	}
}

func CreateSourceZendeskSupportAuthenticationSourceZendeskSupportAPIToken(sourceZendeskSupportAPIToken SourceZendeskSupportAPIToken) SourceZendeskSupportAuthentication {
	typ := SourceZendeskSupportAuthenticationTypeSourceZendeskSupportAPIToken

	return SourceZendeskSupportAuthentication{
		SourceZendeskSupportAPIToken: &sourceZendeskSupportAPIToken,
		Type:                         typ,
	}
}

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

	var sourceZendeskSupportAPIToken SourceZendeskSupportAPIToken = SourceZendeskSupportAPIToken{}
	if err := utils.UnmarshalJSON(data, &sourceZendeskSupportAPIToken, "", true, true); err == nil {
		u.SourceZendeskSupportAPIToken = &sourceZendeskSupportAPIToken
		u.Type = SourceZendeskSupportAuthenticationTypeSourceZendeskSupportAPIToken
		return nil
	}

	var sourceZendeskSupportOAuth20 SourceZendeskSupportOAuth20 = SourceZendeskSupportOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceZendeskSupportOAuth20, "", true, true); err == nil {
		u.SourceZendeskSupportOAuth20 = &sourceZendeskSupportOAuth20
		u.Type = SourceZendeskSupportAuthenticationTypeSourceZendeskSupportOAuth20
		return nil
	}

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

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

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

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

type ZendeskSupport string

const (
	ZendeskSupportZendeskSupport ZendeskSupport = "zendesk-support"
)

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

type SourceZendeskSupport struct {
	// Zendesk allows two authentication methods. We recommend using `OAuth2.0` for Airbyte Cloud users and `API token` for Airbyte Open Source users.
	Credentials *SourceZendeskSupportAuthentication `json:"credentials,omitempty"`
	// The number of worker threads to use for the sync. The performance upper boundary is based on the limit of your Zendesk Support plan. More info about the rate limit plan tiers can be found on Zendesk's API <a href="https://developer.zendesk.com/api-reference/introduction/rate-limits/#zendesk-support-plan-limits">docs</a>.
	NumWorkers *int64 `default:"3" json:"num_workers"`
	// The UTC date and time from which you'd like to replicate data, in the format YYYY-MM-DDT00:00:00Z. All data generated after this date will be replicated.
	StartDate *time.Time `json:"start_date,omitempty"`
	// This is your unique Zendesk subdomain that can be found in your account URL. For example, in https://MY_SUBDOMAIN.zendesk.com/, MY_SUBDOMAIN is the value of your subdomain.
	Subdomain  string         `json:"subdomain"`
	sourceType ZendeskSupport `const:"zendesk-support" json:"sourceType"`
}

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

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

func (o *SourceZendeskSupport) GetCredentials() *SourceZendeskSupportAuthentication {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceZendeskSupport) GetNumWorkers() *int64 {
	if o == nil {
		return nil
	}
	return o.NumWorkers
}

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

func (o *SourceZendeskSupport) GetSubdomain() string {
	if o == nil {
		return ""
	}
	return o.Subdomain
}

func (o *SourceZendeskSupport) GetSourceType() ZendeskSupport {
	return ZendeskSupportZendeskSupport
}
