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

type SourceSurveySparrowUpdateSchemasURLBase string

const (
	SourceSurveySparrowUpdateSchemasURLBaseHTTPSAPISurveysparrowComV3 SourceSurveySparrowUpdateSchemasURLBase = "https://api.surveysparrow.com/v3"
)

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

type SourceSurveySparrowUpdateGlobalAccount struct {
	urlBase *SourceSurveySparrowUpdateSchemasURLBase `const:"https://api.surveysparrow.com/v3" json:"url_base,omitempty"`
}

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

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

func (o *SourceSurveySparrowUpdateGlobalAccount) GetURLBase() *SourceSurveySparrowUpdateSchemasURLBase {
	return SourceSurveySparrowUpdateSchemasURLBaseHTTPSAPISurveysparrowComV3.ToPointer()
}

type SourceSurveySparrowUpdateURLBase string

const (
	SourceSurveySparrowUpdateURLBaseHTTPSEuAPISurveysparrowComV3 SourceSurveySparrowUpdateURLBase = "https://eu-api.surveysparrow.com/v3"
)

func (e SourceSurveySparrowUpdateURLBase) ToPointer() *SourceSurveySparrowUpdateURLBase {
	return &e
}
func (e *SourceSurveySparrowUpdateURLBase) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "https://eu-api.surveysparrow.com/v3":
		*e = SourceSurveySparrowUpdateURLBase(v)
		return nil
	default:
		return fmt.Errorf("invalid value for SourceSurveySparrowUpdateURLBase: %v", v)
	}
}

type SourceSurveySparrowUpdateEUBasedAccount struct {
	urlBase *SourceSurveySparrowUpdateURLBase `const:"https://eu-api.surveysparrow.com/v3" json:"url_base,omitempty"`
}

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

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

func (o *SourceSurveySparrowUpdateEUBasedAccount) GetURLBase() *SourceSurveySparrowUpdateURLBase {
	return SourceSurveySparrowUpdateURLBaseHTTPSEuAPISurveysparrowComV3.ToPointer()
}

type SourceSurveySparrowUpdateBaseURLType string

const (
	SourceSurveySparrowUpdateBaseURLTypeSourceSurveySparrowUpdateEUBasedAccount SourceSurveySparrowUpdateBaseURLType = "source-survey-sparrow-update_EU-based account"
	SourceSurveySparrowUpdateBaseURLTypeSourceSurveySparrowUpdateGlobalAccount  SourceSurveySparrowUpdateBaseURLType = "source-survey-sparrow-update_Global account"
)

// SourceSurveySparrowUpdateBaseURL - Is your account location is EU based? If yes, the base url to retrieve data will be different.
type SourceSurveySparrowUpdateBaseURL struct {
	SourceSurveySparrowUpdateEUBasedAccount *SourceSurveySparrowUpdateEUBasedAccount `queryParam:"inline"`
	SourceSurveySparrowUpdateGlobalAccount  *SourceSurveySparrowUpdateGlobalAccount  `queryParam:"inline"`

	Type SourceSurveySparrowUpdateBaseURLType
}

func CreateSourceSurveySparrowUpdateBaseURLSourceSurveySparrowUpdateEUBasedAccount(sourceSurveySparrowUpdateEUBasedAccount SourceSurveySparrowUpdateEUBasedAccount) SourceSurveySparrowUpdateBaseURL {
	typ := SourceSurveySparrowUpdateBaseURLTypeSourceSurveySparrowUpdateEUBasedAccount

	return SourceSurveySparrowUpdateBaseURL{
		SourceSurveySparrowUpdateEUBasedAccount: &sourceSurveySparrowUpdateEUBasedAccount,
		Type:                                    typ,
	}
}

func CreateSourceSurveySparrowUpdateBaseURLSourceSurveySparrowUpdateGlobalAccount(sourceSurveySparrowUpdateGlobalAccount SourceSurveySparrowUpdateGlobalAccount) SourceSurveySparrowUpdateBaseURL {
	typ := SourceSurveySparrowUpdateBaseURLTypeSourceSurveySparrowUpdateGlobalAccount

	return SourceSurveySparrowUpdateBaseURL{
		SourceSurveySparrowUpdateGlobalAccount: &sourceSurveySparrowUpdateGlobalAccount,
		Type:                                   typ,
	}
}

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

	var sourceSurveySparrowUpdateEUBasedAccount SourceSurveySparrowUpdateEUBasedAccount = SourceSurveySparrowUpdateEUBasedAccount{}
	if err := utils.UnmarshalJSON(data, &sourceSurveySparrowUpdateEUBasedAccount, "", true, true); err == nil {
		u.SourceSurveySparrowUpdateEUBasedAccount = &sourceSurveySparrowUpdateEUBasedAccount
		u.Type = SourceSurveySparrowUpdateBaseURLTypeSourceSurveySparrowUpdateEUBasedAccount
		return nil
	}

	var sourceSurveySparrowUpdateGlobalAccount SourceSurveySparrowUpdateGlobalAccount = SourceSurveySparrowUpdateGlobalAccount{}
	if err := utils.UnmarshalJSON(data, &sourceSurveySparrowUpdateGlobalAccount, "", true, true); err == nil {
		u.SourceSurveySparrowUpdateGlobalAccount = &sourceSurveySparrowUpdateGlobalAccount
		u.Type = SourceSurveySparrowUpdateBaseURLTypeSourceSurveySparrowUpdateGlobalAccount
		return nil
	}

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

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

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

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

type SourceSurveySparrowUpdate struct {
	// Your access token. See <a href="https://developers.surveysparrow.com/rest-apis#authentication">here</a>. The key is case sensitive.
	AccessToken string `json:"access_token"`
	// Is your account location is EU based? If yes, the base url to retrieve data will be different.
	Region *SourceSurveySparrowUpdateBaseURL `json:"region,omitempty"`
	// A List of your survey ids for survey-specific stream
	SurveyID []any `json:"survey_id,omitempty"`
}

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

func (o *SourceSurveySparrowUpdate) GetRegion() *SourceSurveySparrowUpdateBaseURL {
	if o == nil {
		return nil
	}
	return o.Region
}

func (o *SourceSurveySparrowUpdate) GetSurveyID() []any {
	if o == nil {
		return nil
	}
	return o.SurveyID
}
