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

const (
	SourceGoogleSearchConsoleUpdateSchemasAuthTypeService SourceGoogleSearchConsoleUpdateSchemasAuthType = "Service"
)

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

type SourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication struct {
	authType SourceGoogleSearchConsoleUpdateSchemasAuthType `const:"Service" json:"auth_type"`
	// The email of the user which has permissions to access the Google Workspace Admin APIs.
	Email string `json:"email"`
	// The JSON key of the service account to use for authorization. Read more <a href="https://cloud.google.com/iam/docs/creating-managing-service-account-keys">here</a>.
	ServiceAccountInfo string `json:"service_account_info"`
}

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

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

func (o *SourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication) GetAuthType() SourceGoogleSearchConsoleUpdateSchemasAuthType {
	return SourceGoogleSearchConsoleUpdateSchemasAuthTypeService
}

func (o *SourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication) GetEmail() string {
	if o == nil {
		return ""
	}
	return o.Email
}

func (o *SourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication) GetServiceAccountInfo() string {
	if o == nil {
		return ""
	}
	return o.ServiceAccountInfo
}

type SourceGoogleSearchConsoleUpdateAuthType string

const (
	SourceGoogleSearchConsoleUpdateAuthTypeClient SourceGoogleSearchConsoleUpdateAuthType = "Client"
)

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

type SourceGoogleSearchConsoleUpdateOAuth struct {
	// Access token for making authenticated requests. Read more <a href="https://developers.google.com/webmaster-tools/v1/how-tos/authorizing">here</a>.
	AccessToken *string                                 `json:"access_token,omitempty"`
	authType    SourceGoogleSearchConsoleUpdateAuthType `const:"Client" json:"auth_type"`
	// The client ID of your Google Search Console developer application. Read more <a href="https://developers.google.com/webmaster-tools/v1/how-tos/authorizing">here</a>.
	ClientID string `json:"client_id"`
	// The client secret of your Google Search Console developer application. Read more <a href="https://developers.google.com/webmaster-tools/v1/how-tos/authorizing">here</a>.
	ClientSecret string `json:"client_secret"`
	// The token for obtaining a new access token. Read more <a href="https://developers.google.com/webmaster-tools/v1/how-tos/authorizing">here</a>.
	RefreshToken string `json:"refresh_token"`
}

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

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

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

func (o *SourceGoogleSearchConsoleUpdateOAuth) GetAuthType() SourceGoogleSearchConsoleUpdateAuthType {
	return SourceGoogleSearchConsoleUpdateAuthTypeClient
}

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

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

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

type SourceGoogleSearchConsoleUpdateAuthenticationTypeType string

const (
	SourceGoogleSearchConsoleUpdateAuthenticationTypeTypeSourceGoogleSearchConsoleUpdateOAuth                           SourceGoogleSearchConsoleUpdateAuthenticationTypeType = "source-google-search-console-update_OAuth"
	SourceGoogleSearchConsoleUpdateAuthenticationTypeTypeSourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication SourceGoogleSearchConsoleUpdateAuthenticationTypeType = "source-google-search-console-update_Service Account Key Authentication"
)

type SourceGoogleSearchConsoleUpdateAuthenticationType struct {
	SourceGoogleSearchConsoleUpdateOAuth                           *SourceGoogleSearchConsoleUpdateOAuth                           `queryParam:"inline"`
	SourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication *SourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication `queryParam:"inline"`

	Type SourceGoogleSearchConsoleUpdateAuthenticationTypeType
}

func CreateSourceGoogleSearchConsoleUpdateAuthenticationTypeSourceGoogleSearchConsoleUpdateOAuth(sourceGoogleSearchConsoleUpdateOAuth SourceGoogleSearchConsoleUpdateOAuth) SourceGoogleSearchConsoleUpdateAuthenticationType {
	typ := SourceGoogleSearchConsoleUpdateAuthenticationTypeTypeSourceGoogleSearchConsoleUpdateOAuth

	return SourceGoogleSearchConsoleUpdateAuthenticationType{
		SourceGoogleSearchConsoleUpdateOAuth: &sourceGoogleSearchConsoleUpdateOAuth,
		Type:                                 typ,
	}
}

func CreateSourceGoogleSearchConsoleUpdateAuthenticationTypeSourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication(sourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication SourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication) SourceGoogleSearchConsoleUpdateAuthenticationType {
	typ := SourceGoogleSearchConsoleUpdateAuthenticationTypeTypeSourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication

	return SourceGoogleSearchConsoleUpdateAuthenticationType{
		SourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication: &sourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication,
		Type: typ,
	}
}

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

	var sourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication SourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication = SourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication{}
	if err := utils.UnmarshalJSON(data, &sourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication, "", true, true); err == nil {
		u.SourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication = &sourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication
		u.Type = SourceGoogleSearchConsoleUpdateAuthenticationTypeTypeSourceGoogleSearchConsoleUpdateServiceAccountKeyAuthentication
		return nil
	}

	var sourceGoogleSearchConsoleUpdateOAuth SourceGoogleSearchConsoleUpdateOAuth = SourceGoogleSearchConsoleUpdateOAuth{}
	if err := utils.UnmarshalJSON(data, &sourceGoogleSearchConsoleUpdateOAuth, "", true, true); err == nil {
		u.SourceGoogleSearchConsoleUpdateOAuth = &sourceGoogleSearchConsoleUpdateOAuth
		u.Type = SourceGoogleSearchConsoleUpdateAuthenticationTypeTypeSourceGoogleSearchConsoleUpdateOAuth
		return nil
	}

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

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

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

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

// SourceGoogleSearchConsoleUpdateValidEnums - An enumeration of dimensions.
type SourceGoogleSearchConsoleUpdateValidEnums string

const (
	SourceGoogleSearchConsoleUpdateValidEnumsCountry SourceGoogleSearchConsoleUpdateValidEnums = "country"
	SourceGoogleSearchConsoleUpdateValidEnumsDate    SourceGoogleSearchConsoleUpdateValidEnums = "date"
	SourceGoogleSearchConsoleUpdateValidEnumsDevice  SourceGoogleSearchConsoleUpdateValidEnums = "device"
	SourceGoogleSearchConsoleUpdateValidEnumsPage    SourceGoogleSearchConsoleUpdateValidEnums = "page"
	SourceGoogleSearchConsoleUpdateValidEnumsQuery   SourceGoogleSearchConsoleUpdateValidEnums = "query"
)

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

type SourceGoogleSearchConsoleUpdateCustomReportConfig struct {
	// A list of available dimensions. Please note, that for technical reasons `date` is the default dimension which will be included in your query whether you specify it or not. Primary key will consist of your custom dimensions and the default dimension along with `site_url` and `search_type`.
	Dimensions []SourceGoogleSearchConsoleUpdateValidEnums `json:"dimensions,omitempty"`
	// The name of the custom report, this name would be used as stream name
	Name string `json:"name"`
}

func (o *SourceGoogleSearchConsoleUpdateCustomReportConfig) GetDimensions() []SourceGoogleSearchConsoleUpdateValidEnums {
	if o == nil {
		return nil
	}
	return o.Dimensions
}

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

// SourceGoogleSearchConsoleUpdateDataFreshness - If set to 'final', the returned data will include only finalized, stable data. If set to 'all', fresh data will be included. When using Incremental sync mode, we do not recommend setting this parameter to 'all' as it may cause data loss. More information can be found in our <a href='https://docs.airbyte.com/integrations/source/google-search-console'>full documentation</a>.
type SourceGoogleSearchConsoleUpdateDataFreshness string

const (
	SourceGoogleSearchConsoleUpdateDataFreshnessFinal SourceGoogleSearchConsoleUpdateDataFreshness = "final"
	SourceGoogleSearchConsoleUpdateDataFreshnessAll   SourceGoogleSearchConsoleUpdateDataFreshness = "all"
)

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

type SourceGoogleSearchConsoleUpdate struct {
	// Some search analytics streams fail with a 400 error if the specified `aggregationType` is not supported. This is customer implementation dependent and if this error is encountered, enable this setting which will override the existing `aggregationType` to use `auto` which should resolve the stream errors.
	AlwaysUseAggregationTypeAuto *bool                                             `default:"false" json:"always_use_aggregation_type_auto"`
	Authorization                SourceGoogleSearchConsoleUpdateAuthenticationType `json:"authorization"`
	// You can add your Custom Analytics report by creating one.
	CustomReportsArray []SourceGoogleSearchConsoleUpdateCustomReportConfig `json:"custom_reports_array,omitempty"`
	// If set to 'final', the returned data will include only finalized, stable data. If set to 'all', fresh data will be included. When using Incremental sync mode, we do not recommend setting this parameter to 'all' as it may cause data loss. More information can be found in our <a href='https://docs.airbyte.com/integrations/source/google-search-console'>full documentation</a>.
	DataState *SourceGoogleSearchConsoleUpdateDataFreshness `default:"final" json:"data_state"`
	// UTC date in the format YYYY-MM-DD. Any data created after this date will not be replicated. Must be greater or equal to the start date field. Leaving this field blank will replicate all data from the start date onward.
	EndDate *types.Date `json:"end_date,omitempty"`
	// The number of worker threads to use for the sync. For more details on Google Search Console rate limits, refer to the <a href="https://developers.google.com/webmaster-tools/limits">docs</a>.
	NumWorkers *int64 `default:"40" json:"num_workers"`
	// The URLs of the website property attached to your GSC account. Learn more about properties <a href="https://support.google.com/webmasters/answer/34592?hl=en">here</a>.
	SiteUrls []string `json:"site_urls"`
	// UTC date in the format YYYY-MM-DD. Any data before this date will not be replicated.
	StartDate *types.Date `default:"2021-01-01" json:"start_date"`
}

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

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

func (o *SourceGoogleSearchConsoleUpdate) GetAlwaysUseAggregationTypeAuto() *bool {
	if o == nil {
		return nil
	}
	return o.AlwaysUseAggregationTypeAuto
}

func (o *SourceGoogleSearchConsoleUpdate) GetAuthorization() SourceGoogleSearchConsoleUpdateAuthenticationType {
	if o == nil {
		return SourceGoogleSearchConsoleUpdateAuthenticationType{}
	}
	return o.Authorization
}

func (o *SourceGoogleSearchConsoleUpdate) GetCustomReportsArray() []SourceGoogleSearchConsoleUpdateCustomReportConfig {
	if o == nil {
		return nil
	}
	return o.CustomReportsArray
}

func (o *SourceGoogleSearchConsoleUpdate) GetDataState() *SourceGoogleSearchConsoleUpdateDataFreshness {
	if o == nil {
		return nil
	}
	return o.DataState
}

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

func (o *SourceGoogleSearchConsoleUpdate) GetNumWorkers() *int64 {
	if o == nil {
		return nil
	}
	return o.NumWorkers
}

func (o *SourceGoogleSearchConsoleUpdate) GetSiteUrls() []string {
	if o == nil {
		return []string{}
	}
	return o.SiteUrls
}

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