// 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"
	"github.com/airbytehq/terraform-provider-airbyte/internal/sdk/types"
)

type SourceTiktokMarketingSchemasAuthType string

const (
	SourceTiktokMarketingSchemasAuthTypeSandboxAccessToken SourceTiktokMarketingSchemasAuthType = "sandbox_access_token"
)

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

type SandboxAccessToken struct {
	// The long-term authorized access token.
	AccessToken string `json:"access_token"`
	// The Advertiser ID which generated for the developer's Sandbox application.
	AdvertiserID string                                `json:"advertiser_id"`
	authType     *SourceTiktokMarketingSchemasAuthType `const:"sandbox_access_token" json:"auth_type,omitempty"`
}

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

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

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

func (o *SandboxAccessToken) GetAdvertiserID() string {
	if o == nil {
		return ""
	}
	return o.AdvertiserID
}

func (o *SandboxAccessToken) GetAuthType() *SourceTiktokMarketingSchemasAuthType {
	return SourceTiktokMarketingSchemasAuthTypeSandboxAccessToken.ToPointer()
}

type SourceTiktokMarketingAuthType string

const (
	SourceTiktokMarketingAuthTypeOauth20 SourceTiktokMarketingAuthType = "oauth2.0"
)

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

type SourceTiktokMarketingOAuth20 struct {
	// Long-term Authorized Access Token.
	AccessToken string `json:"access_token"`
	// The Advertiser ID to filter reports and streams. Let this empty to retrieve all.
	AdvertiserID *string `json:"advertiser_id,omitempty"`
	// The Developer Application App ID.
	AppID    string                         `json:"app_id"`
	authType *SourceTiktokMarketingAuthType `const:"oauth2.0" json:"auth_type,omitempty"`
	// The Developer Application Secret.
	Secret string `json:"secret"`
}

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

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

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

func (o *SourceTiktokMarketingOAuth20) GetAdvertiserID() *string {
	if o == nil {
		return nil
	}
	return o.AdvertiserID
}

func (o *SourceTiktokMarketingOAuth20) GetAppID() string {
	if o == nil {
		return ""
	}
	return o.AppID
}

func (o *SourceTiktokMarketingOAuth20) GetAuthType() *SourceTiktokMarketingAuthType {
	return SourceTiktokMarketingAuthTypeOauth20.ToPointer()
}

func (o *SourceTiktokMarketingOAuth20) GetSecret() string {
	if o == nil {
		return ""
	}
	return o.Secret
}

type SourceTiktokMarketingAuthenticationMethodType string

const (
	SourceTiktokMarketingAuthenticationMethodTypeSourceTiktokMarketingOAuth20 SourceTiktokMarketingAuthenticationMethodType = "source-tiktok-marketing_OAuth2.0"
	SourceTiktokMarketingAuthenticationMethodTypeSandboxAccessToken           SourceTiktokMarketingAuthenticationMethodType = "Sandbox Access Token"
)

// SourceTiktokMarketingAuthenticationMethod - Authentication method
type SourceTiktokMarketingAuthenticationMethod struct {
	SourceTiktokMarketingOAuth20 *SourceTiktokMarketingOAuth20 `queryParam:"inline"`
	SandboxAccessToken           *SandboxAccessToken           `queryParam:"inline"`

	Type SourceTiktokMarketingAuthenticationMethodType
}

func CreateSourceTiktokMarketingAuthenticationMethodSourceTiktokMarketingOAuth20(sourceTiktokMarketingOAuth20 SourceTiktokMarketingOAuth20) SourceTiktokMarketingAuthenticationMethod {
	typ := SourceTiktokMarketingAuthenticationMethodTypeSourceTiktokMarketingOAuth20

	return SourceTiktokMarketingAuthenticationMethod{
		SourceTiktokMarketingOAuth20: &sourceTiktokMarketingOAuth20,
		Type:                         typ,
	}
}

func CreateSourceTiktokMarketingAuthenticationMethodSandboxAccessToken(sandboxAccessToken SandboxAccessToken) SourceTiktokMarketingAuthenticationMethod {
	typ := SourceTiktokMarketingAuthenticationMethodTypeSandboxAccessToken

	return SourceTiktokMarketingAuthenticationMethod{
		SandboxAccessToken: &sandboxAccessToken,
		Type:               typ,
	}
}

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

	var sandboxAccessToken SandboxAccessToken = SandboxAccessToken{}
	if err := utils.UnmarshalJSON(data, &sandboxAccessToken, "", true, true); err == nil {
		u.SandboxAccessToken = &sandboxAccessToken
		u.Type = SourceTiktokMarketingAuthenticationMethodTypeSandboxAccessToken
		return nil
	}

	var sourceTiktokMarketingOAuth20 SourceTiktokMarketingOAuth20 = SourceTiktokMarketingOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceTiktokMarketingOAuth20, "", true, true); err == nil {
		u.SourceTiktokMarketingOAuth20 = &sourceTiktokMarketingOAuth20
		u.Type = SourceTiktokMarketingAuthenticationMethodTypeSourceTiktokMarketingOAuth20
		return nil
	}

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

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

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

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

type TiktokMarketing string

const (
	TiktokMarketingTiktokMarketing TiktokMarketing = "tiktok-marketing"
)

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

type SourceTiktokMarketing struct {
	// The attribution window in days.
	AttributionWindow *int64 `default:"3" json:"attribution_window"`
	// Authentication method
	Credentials *SourceTiktokMarketingAuthenticationMethod `json:"credentials,omitempty"`
	// The date until which you'd like to replicate data for all incremental streams, in the format YYYY-MM-DD. All data generated between start_date and this date will be replicated. Not setting this option will result in always syncing the data till the current date.
	EndDate *types.Date `json:"end_date,omitempty"`
	// Set to active if you want to include deleted data in report based streams and Ads, Ad Groups and Campaign streams.
	IncludeDeleted *bool `default:"false" json:"include_deleted"`
	// The Start Date in format: YYYY-MM-DD. Any data before this date will not be replicated. If this parameter is not set, all data will be replicated.
	StartDate  *types.Date      `default:"2016-09-01" json:"start_date"`
	sourceType *TiktokMarketing `const:"tiktok-marketing" json:"sourceType,omitempty"`
}

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

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

func (o *SourceTiktokMarketing) GetAttributionWindow() *int64 {
	if o == nil {
		return nil
	}
	return o.AttributionWindow
}

func (o *SourceTiktokMarketing) GetCredentials() *SourceTiktokMarketingAuthenticationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceTiktokMarketing) GetEndDate() *types.Date {
	if o == nil {
		return nil
	}
	return o.EndDate
}

func (o *SourceTiktokMarketing) GetIncludeDeleted() *bool {
	if o == nil {
		return nil
	}
	return o.IncludeDeleted
}

func (o *SourceTiktokMarketing) GetStartDate() *types.Date {
	if o == nil {
		return nil
	}
	return o.StartDate
}

func (o *SourceTiktokMarketing) GetSourceType() *TiktokMarketing {
	return TiktokMarketingTiktokMarketing.ToPointer()
}
