// 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"
)

// DefinitionOfConversionCountInReports - The definition of conversion count in reports. See <a href="https://amplifyv01.docs.apiary.io/#reference/performance-reporting/periodic/retrieve-performance-statistics-for-all-marketer-campaigns-by-periodic-breakdown">the docs</a>.
type DefinitionOfConversionCountInReports string

const (
	DefinitionOfConversionCountInReportsClickViewTime  DefinitionOfConversionCountInReports = "click/view_time"
	DefinitionOfConversionCountInReportsConversionTime DefinitionOfConversionCountInReports = "conversion_time"
)

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

type BothUsernameAndPasswordIsRequiredForAuthenticationRequest string

const (
	BothUsernameAndPasswordIsRequiredForAuthenticationRequestUsernamePassword BothUsernameAndPasswordIsRequiredForAuthenticationRequest = "username_password"
)

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

type SourceOutbrainAmplifyUsernamePassword struct {
	// Add Password for authentication.
	Password string                                                    `json:"password"`
	type_    BothUsernameAndPasswordIsRequiredForAuthenticationRequest `const:"username_password" json:"type"`
	// Add Username for authentication.
	Username string `json:"username"`
}

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

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

func (o *SourceOutbrainAmplifyUsernamePassword) GetPassword() string {
	if o == nil {
		return ""
	}
	return o.Password
}

func (o *SourceOutbrainAmplifyUsernamePassword) GetType() BothUsernameAndPasswordIsRequiredForAuthenticationRequest {
	return BothUsernameAndPasswordIsRequiredForAuthenticationRequestUsernamePassword
}

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

type AccessTokenIsRequiredForAuthenticationRequests string

const (
	AccessTokenIsRequiredForAuthenticationRequestsAccessToken AccessTokenIsRequiredForAuthenticationRequests = "access_token"
)

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

type SourceOutbrainAmplifyAccessToken struct {
	// Access Token for making authenticated requests.
	AccessToken string                                         `json:"access_token"`
	type_       AccessTokenIsRequiredForAuthenticationRequests `const:"access_token" json:"type"`
}

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

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

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

func (o *SourceOutbrainAmplifyAccessToken) GetType() AccessTokenIsRequiredForAuthenticationRequests {
	return AccessTokenIsRequiredForAuthenticationRequestsAccessToken
}

type SourceOutbrainAmplifyAuthenticationMethodType string

const (
	SourceOutbrainAmplifyAuthenticationMethodTypeSourceOutbrainAmplifyAccessToken      SourceOutbrainAmplifyAuthenticationMethodType = "source-outbrain-amplify_Access token"
	SourceOutbrainAmplifyAuthenticationMethodTypeSourceOutbrainAmplifyUsernamePassword SourceOutbrainAmplifyAuthenticationMethodType = "source-outbrain-amplify_Username Password"
)

// SourceOutbrainAmplifyAuthenticationMethod - Credentials for making authenticated requests requires either username/password or access_token.
type SourceOutbrainAmplifyAuthenticationMethod struct {
	SourceOutbrainAmplifyAccessToken      *SourceOutbrainAmplifyAccessToken      `queryParam:"inline"`
	SourceOutbrainAmplifyUsernamePassword *SourceOutbrainAmplifyUsernamePassword `queryParam:"inline"`

	Type SourceOutbrainAmplifyAuthenticationMethodType
}

func CreateSourceOutbrainAmplifyAuthenticationMethodSourceOutbrainAmplifyAccessToken(sourceOutbrainAmplifyAccessToken SourceOutbrainAmplifyAccessToken) SourceOutbrainAmplifyAuthenticationMethod {
	typ := SourceOutbrainAmplifyAuthenticationMethodTypeSourceOutbrainAmplifyAccessToken

	return SourceOutbrainAmplifyAuthenticationMethod{
		SourceOutbrainAmplifyAccessToken: &sourceOutbrainAmplifyAccessToken,
		Type:                             typ,
	}
}

func CreateSourceOutbrainAmplifyAuthenticationMethodSourceOutbrainAmplifyUsernamePassword(sourceOutbrainAmplifyUsernamePassword SourceOutbrainAmplifyUsernamePassword) SourceOutbrainAmplifyAuthenticationMethod {
	typ := SourceOutbrainAmplifyAuthenticationMethodTypeSourceOutbrainAmplifyUsernamePassword

	return SourceOutbrainAmplifyAuthenticationMethod{
		SourceOutbrainAmplifyUsernamePassword: &sourceOutbrainAmplifyUsernamePassword,
		Type:                                  typ,
	}
}

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

	var sourceOutbrainAmplifyAccessToken SourceOutbrainAmplifyAccessToken = SourceOutbrainAmplifyAccessToken{}
	if err := utils.UnmarshalJSON(data, &sourceOutbrainAmplifyAccessToken, "", true, true); err == nil {
		u.SourceOutbrainAmplifyAccessToken = &sourceOutbrainAmplifyAccessToken
		u.Type = SourceOutbrainAmplifyAuthenticationMethodTypeSourceOutbrainAmplifyAccessToken
		return nil
	}

	var sourceOutbrainAmplifyUsernamePassword SourceOutbrainAmplifyUsernamePassword = SourceOutbrainAmplifyUsernamePassword{}
	if err := utils.UnmarshalJSON(data, &sourceOutbrainAmplifyUsernamePassword, "", true, true); err == nil {
		u.SourceOutbrainAmplifyUsernamePassword = &sourceOutbrainAmplifyUsernamePassword
		u.Type = SourceOutbrainAmplifyAuthenticationMethodTypeSourceOutbrainAmplifyUsernamePassword
		return nil
	}

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

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

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

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

// GranularityForGeoLocationRegion - The granularity used for geo location data in reports.
type GranularityForGeoLocationRegion string

const (
	GranularityForGeoLocationRegionCountry   GranularityForGeoLocationRegion = "country"
	GranularityForGeoLocationRegionRegion    GranularityForGeoLocationRegion = "region"
	GranularityForGeoLocationRegionSubregion GranularityForGeoLocationRegion = "subregion"
)

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

// GranularityForPeriodicReports - The granularity used for periodic data in reports. See <a href="https://amplifyv01.docs.apiary.io/#reference/performance-reporting/periodic/retrieve-performance-statistics-for-all-marketer-campaigns-by-periodic-breakdown">the docs</a>.
type GranularityForPeriodicReports string

const (
	GranularityForPeriodicReportsDaily   GranularityForPeriodicReports = "daily"
	GranularityForPeriodicReportsWeekly  GranularityForPeriodicReports = "weekly"
	GranularityForPeriodicReportsMonthly GranularityForPeriodicReports = "monthly"
)

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

type OutbrainAmplify string

const (
	OutbrainAmplifyOutbrainAmplify OutbrainAmplify = "outbrain-amplify"
)

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

type SourceOutbrainAmplify struct {
	// The definition of conversion count in reports. See <a href="https://amplifyv01.docs.apiary.io/#reference/performance-reporting/periodic/retrieve-performance-statistics-for-all-marketer-campaigns-by-periodic-breakdown">the docs</a>.
	ConversionCount *DefinitionOfConversionCountInReports `json:"conversion_count,omitempty"`
	// Credentials for making authenticated requests requires either username/password or access_token.
	Credentials SourceOutbrainAmplifyAuthenticationMethod `json:"credentials"`
	// Date in the format YYYY-MM-DD.
	EndDate *string `json:"end_date,omitempty"`
	// The granularity used for geo location data in reports.
	GeoLocationBreakdown *GranularityForGeoLocationRegion `json:"geo_location_breakdown,omitempty"`
	// The granularity used for periodic data in reports. See <a href="https://amplifyv01.docs.apiary.io/#reference/performance-reporting/periodic/retrieve-performance-statistics-for-all-marketer-campaigns-by-periodic-breakdown">the docs</a>.
	ReportGranularity *GranularityForPeriodicReports `json:"report_granularity,omitempty"`
	// Date in the format YYYY-MM-DD eg. 2017-01-25. Any data before this date will not be replicated.
	StartDate  string          `json:"start_date"`
	sourceType OutbrainAmplify `const:"outbrain-amplify" json:"sourceType"`
}

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

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

func (o *SourceOutbrainAmplify) GetConversionCount() *DefinitionOfConversionCountInReports {
	if o == nil {
		return nil
	}
	return o.ConversionCount
}

func (o *SourceOutbrainAmplify) GetCredentials() SourceOutbrainAmplifyAuthenticationMethod {
	if o == nil {
		return SourceOutbrainAmplifyAuthenticationMethod{}
	}
	return o.Credentials
}

func (o *SourceOutbrainAmplify) GetEndDate() *string {
	if o == nil {
		return nil
	}
	return o.EndDate
}

func (o *SourceOutbrainAmplify) GetGeoLocationBreakdown() *GranularityForGeoLocationRegion {
	if o == nil {
		return nil
	}
	return o.GeoLocationBreakdown
}

func (o *SourceOutbrainAmplify) GetReportGranularity() *GranularityForPeriodicReports {
	if o == nil {
		return nil
	}
	return o.ReportGranularity
}

func (o *SourceOutbrainAmplify) GetStartDate() string {
	if o == nil {
		return ""
	}
	return o.StartDate
}

func (o *SourceOutbrainAmplify) GetSourceType() OutbrainAmplify {
	return OutbrainAmplifyOutbrainAmplify
}
