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

const (
	SourceZendeskSunshineSchemasAuthMethodAPIToken SourceZendeskSunshineSchemasAuthMethod = "api_token"
)

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

type SourceZendeskSunshineAPIToken struct {
	// API Token. See the <a href="https://docs.airbyte.com/integrations/sources/zendesk_sunshine">docs</a> for information on how to generate this key.
	APIToken   string                                  `json:"api_token"`
	authMethod *SourceZendeskSunshineSchemasAuthMethod `const:"api_token" json:"auth_method"`
	// The user email for your Zendesk account
	Email string `json:"email"`
}

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

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

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

func (o *SourceZendeskSunshineAPIToken) GetAuthMethod() *SourceZendeskSunshineSchemasAuthMethod {
	return SourceZendeskSunshineSchemasAuthMethodAPIToken.ToPointer()
}

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

type SourceZendeskSunshineAuthMethod string

const (
	SourceZendeskSunshineAuthMethodOauth20 SourceZendeskSunshineAuthMethod = "oauth2.0"
)

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

type SourceZendeskSunshineOAuth20 struct {
	// Long-term access Token for making authenticated requests.
	AccessToken string                           `json:"access_token"`
	authMethod  *SourceZendeskSunshineAuthMethod `const:"oauth2.0" json:"auth_method"`
	// The Client ID of your OAuth application.
	ClientID string `json:"client_id"`
	// The Client Secret of your OAuth application.
	ClientSecret string `json:"client_secret"`
}

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

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

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

func (o *SourceZendeskSunshineOAuth20) GetAuthMethod() *SourceZendeskSunshineAuthMethod {
	return SourceZendeskSunshineAuthMethodOauth20.ToPointer()
}

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

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

type SourceZendeskSunshineAuthorizationMethodType string

const (
	SourceZendeskSunshineAuthorizationMethodTypeSourceZendeskSunshineOAuth20  SourceZendeskSunshineAuthorizationMethodType = "source-zendesk-sunshine_OAuth2.0"
	SourceZendeskSunshineAuthorizationMethodTypeSourceZendeskSunshineAPIToken SourceZendeskSunshineAuthorizationMethodType = "source-zendesk-sunshine_API Token"
)

type SourceZendeskSunshineAuthorizationMethod struct {
	SourceZendeskSunshineOAuth20  *SourceZendeskSunshineOAuth20  `queryParam:"inline"`
	SourceZendeskSunshineAPIToken *SourceZendeskSunshineAPIToken `queryParam:"inline"`

	Type SourceZendeskSunshineAuthorizationMethodType
}

func CreateSourceZendeskSunshineAuthorizationMethodSourceZendeskSunshineOAuth20(sourceZendeskSunshineOAuth20 SourceZendeskSunshineOAuth20) SourceZendeskSunshineAuthorizationMethod {
	typ := SourceZendeskSunshineAuthorizationMethodTypeSourceZendeskSunshineOAuth20

	return SourceZendeskSunshineAuthorizationMethod{
		SourceZendeskSunshineOAuth20: &sourceZendeskSunshineOAuth20,
		Type:                         typ,
	}
}

func CreateSourceZendeskSunshineAuthorizationMethodSourceZendeskSunshineAPIToken(sourceZendeskSunshineAPIToken SourceZendeskSunshineAPIToken) SourceZendeskSunshineAuthorizationMethod {
	typ := SourceZendeskSunshineAuthorizationMethodTypeSourceZendeskSunshineAPIToken

	return SourceZendeskSunshineAuthorizationMethod{
		SourceZendeskSunshineAPIToken: &sourceZendeskSunshineAPIToken,
		Type:                          typ,
	}
}

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

	var sourceZendeskSunshineAPIToken SourceZendeskSunshineAPIToken = SourceZendeskSunshineAPIToken{}
	if err := utils.UnmarshalJSON(data, &sourceZendeskSunshineAPIToken, "", true, true); err == nil {
		u.SourceZendeskSunshineAPIToken = &sourceZendeskSunshineAPIToken
		u.Type = SourceZendeskSunshineAuthorizationMethodTypeSourceZendeskSunshineAPIToken
		return nil
	}

	var sourceZendeskSunshineOAuth20 SourceZendeskSunshineOAuth20 = SourceZendeskSunshineOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceZendeskSunshineOAuth20, "", true, true); err == nil {
		u.SourceZendeskSunshineOAuth20 = &sourceZendeskSunshineOAuth20
		u.Type = SourceZendeskSunshineAuthorizationMethodTypeSourceZendeskSunshineOAuth20
		return nil
	}

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

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

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

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

type ZendeskSunshine string

const (
	ZendeskSunshineZendeskSunshine ZendeskSunshine = "zendesk-sunshine"
)

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

type SourceZendeskSunshine struct {
	Credentials *SourceZendeskSunshineAuthorizationMethod `json:"credentials,omitempty"`
	// The date from which you'd like to replicate data for Zendesk Sunshine API, in the format YYYY-MM-DDT00:00:00Z.
	StartDate time.Time `json:"start_date"`
	// The subdomain for your Zendesk Account.
	Subdomain  string          `json:"subdomain"`
	sourceType ZendeskSunshine `const:"zendesk-sunshine" json:"sourceType"`
}

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

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

func (o *SourceZendeskSunshine) GetCredentials() *SourceZendeskSunshineAuthorizationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

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

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

func (o *SourceZendeskSunshine) GetSourceType() ZendeskSunshine {
	return ZendeskSunshineZendeskSunshine
}
