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

const (
	SourceSurveySparrowURLBaseHTTPSAPISurveysparrowComV3 SourceSurveySparrowURLBase = "https://api.surveysparrow.com/v3"
)

func (e SourceSurveySparrowURLBase) ToPointer() *SourceSurveySparrowURLBase {
	return &e
}
func (e *SourceSurveySparrowURLBase) 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 = SourceSurveySparrowURLBase(v)
		return nil
	default:
		return fmt.Errorf("invalid value for SourceSurveySparrowURLBase: %v", v)
	}
}

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

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

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

func (o *GlobalAccount) GetURLBase() *SourceSurveySparrowURLBase {
	return SourceSurveySparrowURLBaseHTTPSAPISurveysparrowComV3.ToPointer()
}

type URLBase string

const (
	URLBaseHTTPSEuAPISurveysparrowComV3 URLBase = "https://eu-api.surveysparrow.com/v3"
)

func (e URLBase) ToPointer() *URLBase {
	return &e
}
func (e *URLBase) 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 = URLBase(v)
		return nil
	default:
		return fmt.Errorf("invalid value for URLBase: %v", v)
	}
}

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

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

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

func (o *EUBasedAccount) GetURLBase() *URLBase {
	return URLBaseHTTPSEuAPISurveysparrowComV3.ToPointer()
}

type BaseURLType string

const (
	BaseURLTypeEUBasedAccount BaseURLType = "EU-based account"
	BaseURLTypeGlobalAccount  BaseURLType = "Global account"
)

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

	Type BaseURLType
}

func CreateBaseURLEUBasedAccount(euBasedAccount EUBasedAccount) BaseURL {
	typ := BaseURLTypeEUBasedAccount

	return BaseURL{
		EUBasedAccount: &euBasedAccount,
		Type:           typ,
	}
}

func CreateBaseURLGlobalAccount(globalAccount GlobalAccount) BaseURL {
	typ := BaseURLTypeGlobalAccount

	return BaseURL{
		GlobalAccount: &globalAccount,
		Type:          typ,
	}
}

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

	var euBasedAccount EUBasedAccount = EUBasedAccount{}
	if err := utils.UnmarshalJSON(data, &euBasedAccount, "", true, true); err == nil {
		u.EUBasedAccount = &euBasedAccount
		u.Type = BaseURLTypeEUBasedAccount
		return nil
	}

	var globalAccount GlobalAccount = GlobalAccount{}
	if err := utils.UnmarshalJSON(data, &globalAccount, "", true, true); err == nil {
		u.GlobalAccount = &globalAccount
		u.Type = BaseURLTypeGlobalAccount
		return nil
	}

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

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

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

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

type SurveySparrow string

const (
	SurveySparrowSurveySparrow SurveySparrow = "survey-sparrow"
)

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

type SourceSurveySparrow 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 *BaseURL `json:"region,omitempty"`
	// A List of your survey ids for survey-specific stream
	SurveyID   []any         `json:"survey_id,omitempty"`
	sourceType SurveySparrow `const:"survey-sparrow" json:"sourceType"`
}

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

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

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

func (o *SourceSurveySparrow) GetRegion() *BaseURL {
	if o == nil {
		return nil
	}
	return o.Region
}

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

func (o *SourceSurveySparrow) GetSourceType() SurveySparrow {
	return SurveySparrowSurveySparrow
}
