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

const (
	SourceRdStationMarketingAuthTypeClient SourceRdStationMarketingAuthType = "Client"
)

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

type SignInViaRDStationOAuth struct {
	authType SourceRdStationMarketingAuthType `const:"Client" json:"auth_type"`
	// The Client ID of your RD Station developer application.
	ClientID *string `json:"client_id,omitempty"`
	// The Client Secret of your RD Station developer application
	ClientSecret *string `json:"client_secret,omitempty"`
	// The token for obtaining the new access token.
	RefreshToken *string `json:"refresh_token,omitempty"`
}

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

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

func (o *SignInViaRDStationOAuth) GetAuthType() SourceRdStationMarketingAuthType {
	return SourceRdStationMarketingAuthTypeClient
}

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

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

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

type SourceRdStationMarketingAuthenticationTypeType string

const (
	SourceRdStationMarketingAuthenticationTypeTypeSignInViaRDStationOAuth SourceRdStationMarketingAuthenticationTypeType = "Sign in via RD Station (OAuth)"
)

// SourceRdStationMarketingAuthenticationType - Choose one of the possible authorization method
type SourceRdStationMarketingAuthenticationType struct {
	SignInViaRDStationOAuth *SignInViaRDStationOAuth `queryParam:"inline"`

	Type SourceRdStationMarketingAuthenticationTypeType
}

func CreateSourceRdStationMarketingAuthenticationTypeSignInViaRDStationOAuth(signInViaRDStationOAuth SignInViaRDStationOAuth) SourceRdStationMarketingAuthenticationType {
	typ := SourceRdStationMarketingAuthenticationTypeTypeSignInViaRDStationOAuth

	return SourceRdStationMarketingAuthenticationType{
		SignInViaRDStationOAuth: &signInViaRDStationOAuth,
		Type:                    typ,
	}
}

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

	var signInViaRDStationOAuth SignInViaRDStationOAuth = SignInViaRDStationOAuth{}
	if err := utils.UnmarshalJSON(data, &signInViaRDStationOAuth, "", true, true); err == nil {
		u.SignInViaRDStationOAuth = &signInViaRDStationOAuth
		u.Type = SourceRdStationMarketingAuthenticationTypeTypeSignInViaRDStationOAuth
		return nil
	}

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

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

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

type RdStationMarketing string

const (
	RdStationMarketingRdStationMarketing RdStationMarketing = "rd-station-marketing"
)

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

type SourceRdStationMarketing struct {
	// Choose one of the possible authorization method
	Authorization *SourceRdStationMarketingAuthenticationType `json:"authorization,omitempty"`
	// UTC date and time in the format 2017-01-25T00:00:00Z. Any data before this date will not be replicated. When specified and not None, then stream will behave as incremental
	StartDate  string             `json:"start_date"`
	sourceType RdStationMarketing `const:"rd-station-marketing" json:"sourceType"`
}

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

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

func (o *SourceRdStationMarketing) GetAuthorization() *SourceRdStationMarketingAuthenticationType {
	if o == nil {
		return nil
	}
	return o.Authorization
}

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

func (o *SourceRdStationMarketing) GetSourceType() RdStationMarketing {
	return RdStationMarketingRdStationMarketing
}
