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

const (
	SourceMixpanelSchemasOptionTitleProjectSecret SourceMixpanelSchemasOptionTitle = "Project Secret"
)

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

type ProjectSecret struct {
	// Mixpanel project secret. See the <a href="https://developer.mixpanel.com/reference/project-secret#managing-a-projects-secret">docs</a> for more information on how to obtain this.
	APISecret   string                            `json:"api_secret"`
	optionTitle *SourceMixpanelSchemasOptionTitle `const:"Project Secret" json:"option_title,omitempty"`
}

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

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

func (o *ProjectSecret) GetAPISecret() string {
	if o == nil {
		return ""
	}
	return o.APISecret
}

func (o *ProjectSecret) GetOptionTitle() *SourceMixpanelSchemasOptionTitle {
	return SourceMixpanelSchemasOptionTitleProjectSecret.ToPointer()
}

type SourceMixpanelOptionTitle string

const (
	SourceMixpanelOptionTitleServiceAccount SourceMixpanelOptionTitle = "Service Account"
)

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

type ServiceAccount struct {
	optionTitle *SourceMixpanelOptionTitle `const:"Service Account" json:"option_title,omitempty"`
	// Your project ID number. See the <a href="https://help.mixpanel.com/hc/en-us/articles/115004490503-Project-Settings#project-id">docs</a> for more information on how to obtain this.
	ProjectID int64 `json:"project_id"`
	// Mixpanel Service Account Secret. See the <a href="https://developer.mixpanel.com/reference/service-accounts">docs</a> for more information on how to obtain this.
	Secret string `json:"secret"`
	// Mixpanel Service Account Username. See the <a href="https://developer.mixpanel.com/reference/service-accounts">docs</a> for more information on how to obtain this.
	Username string `json:"username"`
}

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

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

func (o *ServiceAccount) GetOptionTitle() *SourceMixpanelOptionTitle {
	return SourceMixpanelOptionTitleServiceAccount.ToPointer()
}

func (o *ServiceAccount) GetProjectID() int64 {
	if o == nil {
		return 0
	}
	return o.ProjectID
}

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

func (o *ServiceAccount) GetUsername() string {
	if o == nil {
		return ""
	}
	return o.Username
}

type AuthenticationWildcardType string

const (
	AuthenticationWildcardTypeServiceAccount AuthenticationWildcardType = "Service Account"
	AuthenticationWildcardTypeProjectSecret  AuthenticationWildcardType = "Project Secret"
)

// AuthenticationWildcard - Choose how to authenticate to Mixpanel
type AuthenticationWildcard struct {
	ServiceAccount *ServiceAccount `queryParam:"inline"`
	ProjectSecret  *ProjectSecret  `queryParam:"inline"`

	Type AuthenticationWildcardType
}

func CreateAuthenticationWildcardServiceAccount(serviceAccount ServiceAccount) AuthenticationWildcard {
	typ := AuthenticationWildcardTypeServiceAccount

	return AuthenticationWildcard{
		ServiceAccount: &serviceAccount,
		Type:           typ,
	}
}

func CreateAuthenticationWildcardProjectSecret(projectSecret ProjectSecret) AuthenticationWildcard {
	typ := AuthenticationWildcardTypeProjectSecret

	return AuthenticationWildcard{
		ProjectSecret: &projectSecret,
		Type:          typ,
	}
}

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

	var projectSecret ProjectSecret = ProjectSecret{}
	if err := utils.UnmarshalJSON(data, &projectSecret, "", true, true); err == nil {
		u.ProjectSecret = &projectSecret
		u.Type = AuthenticationWildcardTypeProjectSecret
		return nil
	}

	var serviceAccount ServiceAccount = ServiceAccount{}
	if err := utils.UnmarshalJSON(data, &serviceAccount, "", true, true); err == nil {
		u.ServiceAccount = &serviceAccount
		u.Type = AuthenticationWildcardTypeServiceAccount
		return nil
	}

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

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

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

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

// SourceMixpanelRegion - The region of mixpanel domain instance either US or EU.
type SourceMixpanelRegion string

const (
	SourceMixpanelRegionUs SourceMixpanelRegion = "US"
	SourceMixpanelRegionEu SourceMixpanelRegion = "EU"
)

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

type Mixpanel string

const (
	MixpanelMixpanel Mixpanel = "mixpanel"
)

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

type SourceMixpanel struct {
	// A period of time for attributing results to ads and the lookback period after those actions occur during which ad results are counted. Default attribution window is 5 days. (This value should be non-negative integer)
	AttributionWindow *int64 `default:"5" json:"attribution_window"`
	// Choose how to authenticate to Mixpanel
	Credentials AuthenticationWildcard `json:"credentials"`
	// Defines window size in days, that used to slice through data. You can reduce it, if amount of data in each window is too big for your environment. (This value should be positive integer)
	DateWindowSize *int64 `default:"30" json:"date_window_size"`
	// The date in the format YYYY-MM-DD. Any data after this date will not be replicated. Left empty to always sync to most recent date
	EndDate *time.Time `json:"end_date,omitempty"`
	// The number of seconds to look back from the last synced timestamp during incremental syncs of the Export stream. This ensures no data is missed due to delays in event recording. Default is 0 seconds. Must be a non-negative integer.
	ExportLookbackWindow *int64 `default:"0" json:"export_lookback_window"`
	// The number of records to fetch per request for the engage stream. Default is 1000. If you are experiencing long sync times with this stream, try increasing this value.
	PageSize *int64 `default:"1000" json:"page_size"`
	// Time zone in which integer date times are stored. The project timezone may be found in the project settings in the <a href="https://help.mixpanel.com/hc/en-us/articles/115004547203-Manage-Timezones-for-Projects-in-Mixpanel">Mixpanel console</a>.
	ProjectTimezone *string `default:"US/Pacific" json:"project_timezone"`
	// The region of mixpanel domain instance either US or EU.
	Region *SourceMixpanelRegion `default:"US" json:"region"`
	// Setting this config parameter to TRUE ensures that new properties on events and engage records are captured. Otherwise new properties will be ignored.
	SelectPropertiesByDefault *bool `default:"true" json:"select_properties_by_default"`
	// The date in the format YYYY-MM-DD. Any data before this date will not be replicated. If this option is not set, the connector will replicate data from up to one year ago by default.
	StartDate  *time.Time `json:"start_date,omitempty"`
	sourceType Mixpanel   `const:"mixpanel" json:"sourceType"`
}

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

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

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

func (o *SourceMixpanel) GetCredentials() AuthenticationWildcard {
	if o == nil {
		return AuthenticationWildcard{}
	}
	return o.Credentials
}

func (o *SourceMixpanel) GetDateWindowSize() *int64 {
	if o == nil {
		return nil
	}
	return o.DateWindowSize
}

func (o *SourceMixpanel) GetEndDate() *time.Time {
	if o == nil {
		return nil
	}
	return o.EndDate
}

func (o *SourceMixpanel) GetExportLookbackWindow() *int64 {
	if o == nil {
		return nil
	}
	return o.ExportLookbackWindow
}

func (o *SourceMixpanel) GetPageSize() *int64 {
	if o == nil {
		return nil
	}
	return o.PageSize
}

func (o *SourceMixpanel) GetProjectTimezone() *string {
	if o == nil {
		return nil
	}
	return o.ProjectTimezone
}

func (o *SourceMixpanel) GetRegion() *SourceMixpanelRegion {
	if o == nil {
		return nil
	}
	return o.Region
}

func (o *SourceMixpanel) GetSelectPropertiesByDefault() *bool {
	if o == nil {
		return nil
	}
	return o.SelectPropertiesByDefault
}

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

func (o *SourceMixpanel) GetSourceType() Mixpanel {
	return MixpanelMixpanel
}
