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

const (
	SourceCartUpdateSchemasAuthTypeSingleStoreAccessToken SourceCartUpdateSchemasAuthType = "SINGLE_STORE_ACCESS_TOKEN"
)

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

type SourceCartUpdateSingleStoreAccessToken struct {
	// Access Token for making authenticated requests.
	AccessToken string                          `json:"access_token"`
	authType    SourceCartUpdateSchemasAuthType `const:"SINGLE_STORE_ACCESS_TOKEN" json:"auth_type"`
	// The name of Cart.com Online Store. All API URLs start with https://[mystorename.com]/api/v1/, where [mystorename.com] is the domain name of your store.
	StoreName string `json:"store_name"`
}

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

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

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

func (o *SourceCartUpdateSingleStoreAccessToken) GetAuthType() SourceCartUpdateSchemasAuthType {
	return SourceCartUpdateSchemasAuthTypeSingleStoreAccessToken
}

func (o *SourceCartUpdateSingleStoreAccessToken) GetStoreName() string {
	if o == nil {
		return ""
	}
	return o.StoreName
}

type SourceCartUpdateAuthType string

const (
	SourceCartUpdateAuthTypeCentralAPIRouter SourceCartUpdateAuthType = "CENTRAL_API_ROUTER"
)

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

type SourceCartUpdateCentralAPIRouter struct {
	authType SourceCartUpdateAuthType `const:"CENTRAL_API_ROUTER" json:"auth_type"`
	// You can determine a site provisioning site Id by hitting https://site.com/store/sitemonitor.aspx and reading the response param PSID
	SiteID string `json:"site_id"`
	// Enter your application's User Name
	UserName string `json:"user_name"`
	// Enter your application's User Secret
	UserSecret string `json:"user_secret"`
}

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

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

func (o *SourceCartUpdateCentralAPIRouter) GetAuthType() SourceCartUpdateAuthType {
	return SourceCartUpdateAuthTypeCentralAPIRouter
}

func (o *SourceCartUpdateCentralAPIRouter) GetSiteID() string {
	if o == nil {
		return ""
	}
	return o.SiteID
}

func (o *SourceCartUpdateCentralAPIRouter) GetUserName() string {
	if o == nil {
		return ""
	}
	return o.UserName
}

func (o *SourceCartUpdateCentralAPIRouter) GetUserSecret() string {
	if o == nil {
		return ""
	}
	return o.UserSecret
}

type SourceCartUpdateAuthorizationMethodType string

const (
	SourceCartUpdateAuthorizationMethodTypeSourceCartUpdateCentralAPIRouter       SourceCartUpdateAuthorizationMethodType = "source-cart-update_Central API Router"
	SourceCartUpdateAuthorizationMethodTypeSourceCartUpdateSingleStoreAccessToken SourceCartUpdateAuthorizationMethodType = "source-cart-update_Single Store Access Token"
)

type SourceCartUpdateAuthorizationMethod struct {
	SourceCartUpdateCentralAPIRouter       *SourceCartUpdateCentralAPIRouter       `queryParam:"inline"`
	SourceCartUpdateSingleStoreAccessToken *SourceCartUpdateSingleStoreAccessToken `queryParam:"inline"`

	Type SourceCartUpdateAuthorizationMethodType
}

func CreateSourceCartUpdateAuthorizationMethodSourceCartUpdateCentralAPIRouter(sourceCartUpdateCentralAPIRouter SourceCartUpdateCentralAPIRouter) SourceCartUpdateAuthorizationMethod {
	typ := SourceCartUpdateAuthorizationMethodTypeSourceCartUpdateCentralAPIRouter

	return SourceCartUpdateAuthorizationMethod{
		SourceCartUpdateCentralAPIRouter: &sourceCartUpdateCentralAPIRouter,
		Type:                             typ,
	}
}

func CreateSourceCartUpdateAuthorizationMethodSourceCartUpdateSingleStoreAccessToken(sourceCartUpdateSingleStoreAccessToken SourceCartUpdateSingleStoreAccessToken) SourceCartUpdateAuthorizationMethod {
	typ := SourceCartUpdateAuthorizationMethodTypeSourceCartUpdateSingleStoreAccessToken

	return SourceCartUpdateAuthorizationMethod{
		SourceCartUpdateSingleStoreAccessToken: &sourceCartUpdateSingleStoreAccessToken,
		Type:                                   typ,
	}
}

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

	var sourceCartUpdateSingleStoreAccessToken SourceCartUpdateSingleStoreAccessToken = SourceCartUpdateSingleStoreAccessToken{}
	if err := utils.UnmarshalJSON(data, &sourceCartUpdateSingleStoreAccessToken, "", true, true); err == nil {
		u.SourceCartUpdateSingleStoreAccessToken = &sourceCartUpdateSingleStoreAccessToken
		u.Type = SourceCartUpdateAuthorizationMethodTypeSourceCartUpdateSingleStoreAccessToken
		return nil
	}

	var sourceCartUpdateCentralAPIRouter SourceCartUpdateCentralAPIRouter = SourceCartUpdateCentralAPIRouter{}
	if err := utils.UnmarshalJSON(data, &sourceCartUpdateCentralAPIRouter, "", true, true); err == nil {
		u.SourceCartUpdateCentralAPIRouter = &sourceCartUpdateCentralAPIRouter
		u.Type = SourceCartUpdateAuthorizationMethodTypeSourceCartUpdateCentralAPIRouter
		return nil
	}

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

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

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

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

type SourceCartUpdate struct {
	Credentials *SourceCartUpdateAuthorizationMethod `json:"credentials,omitempty"`
	// The date from which you'd like to replicate the data
	StartDate string `json:"start_date"`
}

func (o *SourceCartUpdate) GetCredentials() *SourceCartUpdateAuthorizationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

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