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

const (
	SourceZendeskChatSchemasCredentialsAccessToken SourceZendeskChatSchemasCredentials = "access_token"
)

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

type SourceZendeskChatAccessToken struct {
	// The Access Token to make authenticated requests.
	AccessToken string                              `json:"access_token"`
	credentials SourceZendeskChatSchemasCredentials `const:"access_token" json:"credentials"`
}

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

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

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

func (o *SourceZendeskChatAccessToken) GetCredentials() SourceZendeskChatSchemasCredentials {
	return SourceZendeskChatSchemasCredentialsAccessToken
}

type SourceZendeskChatCredentials string

const (
	SourceZendeskChatCredentialsOauth20 SourceZendeskChatCredentials = "oauth2.0"
)

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

type SourceZendeskChatOAuth20 struct {
	// Access Token for making authenticated requests.
	AccessToken *string `json:"access_token,omitempty"`
	// The Client ID of your OAuth application
	ClientID *string `json:"client_id,omitempty"`
	// The Client Secret of your OAuth application.
	ClientSecret *string                      `json:"client_secret,omitempty"`
	credentials  SourceZendeskChatCredentials `const:"oauth2.0" json:"credentials"`
	// Refresh Token to obtain new Access Token, when it's expired.
	RefreshToken *string `json:"refresh_token,omitempty"`
}

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

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

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

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

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

func (o *SourceZendeskChatOAuth20) GetCredentials() SourceZendeskChatCredentials {
	return SourceZendeskChatCredentialsOauth20
}

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

type SourceZendeskChatAuthorizationMethodType string

const (
	SourceZendeskChatAuthorizationMethodTypeSourceZendeskChatOAuth20     SourceZendeskChatAuthorizationMethodType = "source-zendesk-chat_OAuth2.0"
	SourceZendeskChatAuthorizationMethodTypeSourceZendeskChatAccessToken SourceZendeskChatAuthorizationMethodType = "source-zendesk-chat_Access Token"
)

type SourceZendeskChatAuthorizationMethod struct {
	SourceZendeskChatOAuth20     *SourceZendeskChatOAuth20     `queryParam:"inline"`
	SourceZendeskChatAccessToken *SourceZendeskChatAccessToken `queryParam:"inline"`

	Type SourceZendeskChatAuthorizationMethodType
}

func CreateSourceZendeskChatAuthorizationMethodSourceZendeskChatOAuth20(sourceZendeskChatOAuth20 SourceZendeskChatOAuth20) SourceZendeskChatAuthorizationMethod {
	typ := SourceZendeskChatAuthorizationMethodTypeSourceZendeskChatOAuth20

	return SourceZendeskChatAuthorizationMethod{
		SourceZendeskChatOAuth20: &sourceZendeskChatOAuth20,
		Type:                     typ,
	}
}

func CreateSourceZendeskChatAuthorizationMethodSourceZendeskChatAccessToken(sourceZendeskChatAccessToken SourceZendeskChatAccessToken) SourceZendeskChatAuthorizationMethod {
	typ := SourceZendeskChatAuthorizationMethodTypeSourceZendeskChatAccessToken

	return SourceZendeskChatAuthorizationMethod{
		SourceZendeskChatAccessToken: &sourceZendeskChatAccessToken,
		Type:                         typ,
	}
}

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

	var sourceZendeskChatAccessToken SourceZendeskChatAccessToken = SourceZendeskChatAccessToken{}
	if err := utils.UnmarshalJSON(data, &sourceZendeskChatAccessToken, "", true, true); err == nil {
		u.SourceZendeskChatAccessToken = &sourceZendeskChatAccessToken
		u.Type = SourceZendeskChatAuthorizationMethodTypeSourceZendeskChatAccessToken
		return nil
	}

	var sourceZendeskChatOAuth20 SourceZendeskChatOAuth20 = SourceZendeskChatOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceZendeskChatOAuth20, "", true, true); err == nil {
		u.SourceZendeskChatOAuth20 = &sourceZendeskChatOAuth20
		u.Type = SourceZendeskChatAuthorizationMethodTypeSourceZendeskChatOAuth20
		return nil
	}

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

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

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

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

type ZendeskChat string

const (
	ZendeskChatZendeskChat ZendeskChat = "zendesk-chat"
)

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

type SourceZendeskChat struct {
	Credentials *SourceZendeskChatAuthorizationMethod `json:"credentials,omitempty"`
	// The date from which you'd like to replicate data for Zendesk Chat API, in the format YYYY-MM-DDT00:00:00Z.
	StartDate time.Time `json:"start_date"`
	// The unique subdomain of your Zendesk account (without https://). <a href=\"https://support.zendesk.com/hc/en-us/articles/4409381383578-Where-can-I-find-my-Zendesk-subdomain\">See the Zendesk docs to find your subdomain</a>.
	Subdomain  string      `json:"subdomain"`
	sourceType ZendeskChat `const:"zendesk-chat" json:"sourceType"`
}

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

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

func (o *SourceZendeskChat) GetCredentials() *SourceZendeskChatAuthorizationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

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

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

func (o *SourceZendeskChat) GetSourceType() ZendeskChat {
	return ZendeskChatZendeskChat
}
