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

// SourceLinkedinAdsUpdatePivotCategory - Choose a category to pivot your analytics report around. This selection will organize your data based on the chosen attribute, allowing you to analyze trends and performance from different perspectives.
type SourceLinkedinAdsUpdatePivotCategory string

const (
	SourceLinkedinAdsUpdatePivotCategoryCompany                     SourceLinkedinAdsUpdatePivotCategory = "COMPANY"
	SourceLinkedinAdsUpdatePivotCategoryAccount                     SourceLinkedinAdsUpdatePivotCategory = "ACCOUNT"
	SourceLinkedinAdsUpdatePivotCategoryShare                       SourceLinkedinAdsUpdatePivotCategory = "SHARE"
	SourceLinkedinAdsUpdatePivotCategoryCampaign                    SourceLinkedinAdsUpdatePivotCategory = "CAMPAIGN"
	SourceLinkedinAdsUpdatePivotCategoryCreative                    SourceLinkedinAdsUpdatePivotCategory = "CREATIVE"
	SourceLinkedinAdsUpdatePivotCategoryCampaignGroup               SourceLinkedinAdsUpdatePivotCategory = "CAMPAIGN_GROUP"
	SourceLinkedinAdsUpdatePivotCategoryConversion                  SourceLinkedinAdsUpdatePivotCategory = "CONVERSION"
	SourceLinkedinAdsUpdatePivotCategoryConversationNode            SourceLinkedinAdsUpdatePivotCategory = "CONVERSATION_NODE"
	SourceLinkedinAdsUpdatePivotCategoryConversationNodeOptionIndex SourceLinkedinAdsUpdatePivotCategory = "CONVERSATION_NODE_OPTION_INDEX"
	SourceLinkedinAdsUpdatePivotCategoryServingLocation             SourceLinkedinAdsUpdatePivotCategory = "SERVING_LOCATION"
	SourceLinkedinAdsUpdatePivotCategoryCardIndex                   SourceLinkedinAdsUpdatePivotCategory = "CARD_INDEX"
	SourceLinkedinAdsUpdatePivotCategoryMemberCompanySize           SourceLinkedinAdsUpdatePivotCategory = "MEMBER_COMPANY_SIZE"
	SourceLinkedinAdsUpdatePivotCategoryMemberIndustry              SourceLinkedinAdsUpdatePivotCategory = "MEMBER_INDUSTRY"
	SourceLinkedinAdsUpdatePivotCategoryMemberSeniority             SourceLinkedinAdsUpdatePivotCategory = "MEMBER_SENIORITY"
	SourceLinkedinAdsUpdatePivotCategoryMemberJobTitle              SourceLinkedinAdsUpdatePivotCategory = "MEMBER_JOB_TITLE"
	SourceLinkedinAdsUpdatePivotCategoryMemberJobFunction           SourceLinkedinAdsUpdatePivotCategory = "MEMBER_JOB_FUNCTION"
	SourceLinkedinAdsUpdatePivotCategoryMemberCountryV2             SourceLinkedinAdsUpdatePivotCategory = "MEMBER_COUNTRY_V2"
	SourceLinkedinAdsUpdatePivotCategoryMemberRegionV2              SourceLinkedinAdsUpdatePivotCategory = "MEMBER_REGION_V2"
	SourceLinkedinAdsUpdatePivotCategoryMemberCompany               SourceLinkedinAdsUpdatePivotCategory = "MEMBER_COMPANY"
	SourceLinkedinAdsUpdatePivotCategoryPlacementName               SourceLinkedinAdsUpdatePivotCategory = "PLACEMENT_NAME"
	SourceLinkedinAdsUpdatePivotCategoryImpressionDeviceType        SourceLinkedinAdsUpdatePivotCategory = "IMPRESSION_DEVICE_TYPE"
)

func (e SourceLinkedinAdsUpdatePivotCategory) ToPointer() *SourceLinkedinAdsUpdatePivotCategory {
	return &e
}
func (e *SourceLinkedinAdsUpdatePivotCategory) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "COMPANY":
		fallthrough
	case "ACCOUNT":
		fallthrough
	case "SHARE":
		fallthrough
	case "CAMPAIGN":
		fallthrough
	case "CREATIVE":
		fallthrough
	case "CAMPAIGN_GROUP":
		fallthrough
	case "CONVERSION":
		fallthrough
	case "CONVERSATION_NODE":
		fallthrough
	case "CONVERSATION_NODE_OPTION_INDEX":
		fallthrough
	case "SERVING_LOCATION":
		fallthrough
	case "CARD_INDEX":
		fallthrough
	case "MEMBER_COMPANY_SIZE":
		fallthrough
	case "MEMBER_INDUSTRY":
		fallthrough
	case "MEMBER_SENIORITY":
		fallthrough
	case "MEMBER_JOB_TITLE":
		fallthrough
	case "MEMBER_JOB_FUNCTION":
		fallthrough
	case "MEMBER_COUNTRY_V2":
		fallthrough
	case "MEMBER_REGION_V2":
		fallthrough
	case "MEMBER_COMPANY":
		fallthrough
	case "PLACEMENT_NAME":
		fallthrough
	case "IMPRESSION_DEVICE_TYPE":
		*e = SourceLinkedinAdsUpdatePivotCategory(v)
		return nil
	default:
		return fmt.Errorf("invalid value for SourceLinkedinAdsUpdatePivotCategory: %v", v)
	}
}

// SourceLinkedinAdsUpdateTimeGranularity - Choose how to group the data in your report by time. The options are:<br>- 'ALL': A single result summarizing the entire time range.<br>- 'DAILY': Group results by each day.<br>- 'MONTHLY': Group results by each month.<br>- 'YEARLY': Group results by each year.<br>Selecting a time grouping helps you analyze trends and patterns over different time periods.
type SourceLinkedinAdsUpdateTimeGranularity string

const (
	SourceLinkedinAdsUpdateTimeGranularityAll     SourceLinkedinAdsUpdateTimeGranularity = "ALL"
	SourceLinkedinAdsUpdateTimeGranularityDaily   SourceLinkedinAdsUpdateTimeGranularity = "DAILY"
	SourceLinkedinAdsUpdateTimeGranularityMonthly SourceLinkedinAdsUpdateTimeGranularity = "MONTHLY"
	SourceLinkedinAdsUpdateTimeGranularityYearly  SourceLinkedinAdsUpdateTimeGranularity = "YEARLY"
)

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

// SourceLinkedinAdsUpdateAdAnalyticsReportConfiguration - Config for custom ad Analytics Report
type SourceLinkedinAdsUpdateAdAnalyticsReportConfiguration struct {
	// The name for the custom report.
	Name string `json:"name"`
	// Choose a category to pivot your analytics report around. This selection will organize your data based on the chosen attribute, allowing you to analyze trends and performance from different perspectives.
	PivotBy SourceLinkedinAdsUpdatePivotCategory `json:"pivot_by"`
	// Choose how to group the data in your report by time. The options are:<br>- 'ALL': A single result summarizing the entire time range.<br>- 'DAILY': Group results by each day.<br>- 'MONTHLY': Group results by each month.<br>- 'YEARLY': Group results by each year.<br>Selecting a time grouping helps you analyze trends and patterns over different time periods.
	TimeGranularity SourceLinkedinAdsUpdateTimeGranularity `json:"time_granularity"`
}

func (o *SourceLinkedinAdsUpdateAdAnalyticsReportConfiguration) GetName() string {
	if o == nil {
		return ""
	}
	return o.Name
}

func (o *SourceLinkedinAdsUpdateAdAnalyticsReportConfiguration) GetPivotBy() SourceLinkedinAdsUpdatePivotCategory {
	if o == nil {
		return SourceLinkedinAdsUpdatePivotCategory("")
	}
	return o.PivotBy
}

func (o *SourceLinkedinAdsUpdateAdAnalyticsReportConfiguration) GetTimeGranularity() SourceLinkedinAdsUpdateTimeGranularity {
	if o == nil {
		return SourceLinkedinAdsUpdateTimeGranularity("")
	}
	return o.TimeGranularity
}

type SourceLinkedinAdsUpdateSchemasAuthMethod string

const (
	SourceLinkedinAdsUpdateSchemasAuthMethodAccessToken SourceLinkedinAdsUpdateSchemasAuthMethod = "access_token"
)

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

type SourceLinkedinAdsUpdateAccessToken struct {
	// The access token generated for your developer application. Refer to our <a href='https://docs.airbyte.com/integrations/sources/linkedin-ads#setup-guide'>documentation</a> for more information.
	AccessToken string                                    `json:"access_token"`
	authMethod  *SourceLinkedinAdsUpdateSchemasAuthMethod `const:"access_token" json:"auth_method,omitempty"`
}

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

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

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

func (o *SourceLinkedinAdsUpdateAccessToken) GetAuthMethod() *SourceLinkedinAdsUpdateSchemasAuthMethod {
	return SourceLinkedinAdsUpdateSchemasAuthMethodAccessToken.ToPointer()
}

type SourceLinkedinAdsUpdateAuthMethod string

const (
	SourceLinkedinAdsUpdateAuthMethodOAuth20 SourceLinkedinAdsUpdateAuthMethod = "oAuth2.0"
)

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

type SourceLinkedinAdsUpdateOAuth20 struct {
	authMethod *SourceLinkedinAdsUpdateAuthMethod `const:"oAuth2.0" json:"auth_method,omitempty"`
	// The client ID of your developer application. Refer to our <a href='https://docs.airbyte.com/integrations/sources/linkedin-ads#setup-guide'>documentation</a> for more information.
	ClientID string `json:"client_id"`
	// The client secret of your developer application. Refer to our <a href='https://docs.airbyte.com/integrations/sources/linkedin-ads#setup-guide'>documentation</a> for more information.
	ClientSecret string `json:"client_secret"`
	// The key to refresh the expired access token. Refer to our <a href='https://docs.airbyte.com/integrations/sources/linkedin-ads#setup-guide'>documentation</a> for more information.
	RefreshToken string `json:"refresh_token"`
}

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

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

func (o *SourceLinkedinAdsUpdateOAuth20) GetAuthMethod() *SourceLinkedinAdsUpdateAuthMethod {
	return SourceLinkedinAdsUpdateAuthMethodOAuth20.ToPointer()
}

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

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

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

type SourceLinkedinAdsUpdateAuthenticationType string

const (
	SourceLinkedinAdsUpdateAuthenticationTypeSourceLinkedinAdsUpdateOAuth20     SourceLinkedinAdsUpdateAuthenticationType = "source-linkedin-ads-update_OAuth2.0"
	SourceLinkedinAdsUpdateAuthenticationTypeSourceLinkedinAdsUpdateAccessToken SourceLinkedinAdsUpdateAuthenticationType = "source-linkedin-ads-update_Access Token"
)

type SourceLinkedinAdsUpdateAuthentication struct {
	SourceLinkedinAdsUpdateOAuth20     *SourceLinkedinAdsUpdateOAuth20     `queryParam:"inline"`
	SourceLinkedinAdsUpdateAccessToken *SourceLinkedinAdsUpdateAccessToken `queryParam:"inline"`

	Type SourceLinkedinAdsUpdateAuthenticationType
}

func CreateSourceLinkedinAdsUpdateAuthenticationSourceLinkedinAdsUpdateOAuth20(sourceLinkedinAdsUpdateOAuth20 SourceLinkedinAdsUpdateOAuth20) SourceLinkedinAdsUpdateAuthentication {
	typ := SourceLinkedinAdsUpdateAuthenticationTypeSourceLinkedinAdsUpdateOAuth20

	return SourceLinkedinAdsUpdateAuthentication{
		SourceLinkedinAdsUpdateOAuth20: &sourceLinkedinAdsUpdateOAuth20,
		Type:                           typ,
	}
}

func CreateSourceLinkedinAdsUpdateAuthenticationSourceLinkedinAdsUpdateAccessToken(sourceLinkedinAdsUpdateAccessToken SourceLinkedinAdsUpdateAccessToken) SourceLinkedinAdsUpdateAuthentication {
	typ := SourceLinkedinAdsUpdateAuthenticationTypeSourceLinkedinAdsUpdateAccessToken

	return SourceLinkedinAdsUpdateAuthentication{
		SourceLinkedinAdsUpdateAccessToken: &sourceLinkedinAdsUpdateAccessToken,
		Type:                               typ,
	}
}

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

	var sourceLinkedinAdsUpdateAccessToken SourceLinkedinAdsUpdateAccessToken = SourceLinkedinAdsUpdateAccessToken{}
	if err := utils.UnmarshalJSON(data, &sourceLinkedinAdsUpdateAccessToken, "", true, true); err == nil {
		u.SourceLinkedinAdsUpdateAccessToken = &sourceLinkedinAdsUpdateAccessToken
		u.Type = SourceLinkedinAdsUpdateAuthenticationTypeSourceLinkedinAdsUpdateAccessToken
		return nil
	}

	var sourceLinkedinAdsUpdateOAuth20 SourceLinkedinAdsUpdateOAuth20 = SourceLinkedinAdsUpdateOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceLinkedinAdsUpdateOAuth20, "", true, true); err == nil {
		u.SourceLinkedinAdsUpdateOAuth20 = &sourceLinkedinAdsUpdateOAuth20
		u.Type = SourceLinkedinAdsUpdateAuthenticationTypeSourceLinkedinAdsUpdateOAuth20
		return nil
	}

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

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

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

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

type SourceLinkedinAdsUpdate struct {
	// Specify the account IDs to pull data from, separated by a space. Leave this field empty if you want to pull the data from all accounts accessible by the authenticated user. See the <a href="https://www.linkedin.com/help/linkedin/answer/a424270/find-linkedin-ads-account-details?lang=en">LinkedIn docs</a> to locate these IDs.
	AccountIds         []int64                                                 `json:"account_ids,omitempty"`
	AdAnalyticsReports []SourceLinkedinAdsUpdateAdAnalyticsReportConfiguration `json:"ad_analytics_reports,omitempty"`
	Credentials        *SourceLinkedinAdsUpdateAuthentication                  `json:"credentials,omitempty"`
	// How far into the past to look for records. (in days)
	LookbackWindow *int64 `default:"0" json:"lookback_window"`
	// UTC date in the format YYYY-MM-DD. Any data before this date will not be replicated.
	StartDate types.Date `json:"start_date"`
}

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

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

func (o *SourceLinkedinAdsUpdate) GetAccountIds() []int64 {
	if o == nil {
		return nil
	}
	return o.AccountIds
}

func (o *SourceLinkedinAdsUpdate) GetAdAnalyticsReports() []SourceLinkedinAdsUpdateAdAnalyticsReportConfiguration {
	if o == nil {
		return nil
	}
	return o.AdAnalyticsReports
}

func (o *SourceLinkedinAdsUpdate) GetCredentials() *SourceLinkedinAdsUpdateAuthentication {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceLinkedinAdsUpdate) GetLookbackWindow() *int64 {
	if o == nil {
		return nil
	}
	return o.LookbackWindow
}

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