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

const (
	SourceDriftUpdateSchemasCredentialsAccessToken SourceDriftUpdateSchemasCredentials = "access_token"
)

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

type SourceDriftUpdateAccessToken struct {
	// Drift Access Token. See the <a href="https://docs.airbyte.com/integrations/sources/drift">docs</a> for more information on how to generate this key.
	AccessToken string                               `json:"access_token"`
	credentials *SourceDriftUpdateSchemasCredentials `const:"access_token" json:"credentials,omitempty"`
}

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

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

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

func (o *SourceDriftUpdateAccessToken) GetCredentials() *SourceDriftUpdateSchemasCredentials {
	return SourceDriftUpdateSchemasCredentialsAccessToken.ToPointer()
}

type SourceDriftUpdateCredentials string

const (
	SourceDriftUpdateCredentialsOauth20 SourceDriftUpdateCredentials = "oauth2.0"
)

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

type SourceDriftUpdateOAuth20 struct {
	// Access Token for making authenticated requests.
	AccessToken string `json:"access_token"`
	// The Client ID of your Drift developer application.
	ClientID string `json:"client_id"`
	// The Client Secret of your Drift developer application.
	ClientSecret string                        `json:"client_secret"`
	credentials  *SourceDriftUpdateCredentials `const:"oauth2.0" json:"credentials,omitempty"`
	// Refresh Token to renew the expired Access Token.
	RefreshToken string `json:"refresh_token"`
}

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

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

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

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

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

func (o *SourceDriftUpdateOAuth20) GetCredentials() *SourceDriftUpdateCredentials {
	return SourceDriftUpdateCredentialsOauth20.ToPointer()
}

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

type SourceDriftUpdateAuthorizationMethodType string

const (
	SourceDriftUpdateAuthorizationMethodTypeSourceDriftUpdateOAuth20     SourceDriftUpdateAuthorizationMethodType = "source-drift-update_OAuth2.0"
	SourceDriftUpdateAuthorizationMethodTypeSourceDriftUpdateAccessToken SourceDriftUpdateAuthorizationMethodType = "source-drift-update_Access Token"
)

type SourceDriftUpdateAuthorizationMethod struct {
	SourceDriftUpdateOAuth20     *SourceDriftUpdateOAuth20     `queryParam:"inline"`
	SourceDriftUpdateAccessToken *SourceDriftUpdateAccessToken `queryParam:"inline"`

	Type SourceDriftUpdateAuthorizationMethodType
}

func CreateSourceDriftUpdateAuthorizationMethodSourceDriftUpdateOAuth20(sourceDriftUpdateOAuth20 SourceDriftUpdateOAuth20) SourceDriftUpdateAuthorizationMethod {
	typ := SourceDriftUpdateAuthorizationMethodTypeSourceDriftUpdateOAuth20

	return SourceDriftUpdateAuthorizationMethod{
		SourceDriftUpdateOAuth20: &sourceDriftUpdateOAuth20,
		Type:                     typ,
	}
}

func CreateSourceDriftUpdateAuthorizationMethodSourceDriftUpdateAccessToken(sourceDriftUpdateAccessToken SourceDriftUpdateAccessToken) SourceDriftUpdateAuthorizationMethod {
	typ := SourceDriftUpdateAuthorizationMethodTypeSourceDriftUpdateAccessToken

	return SourceDriftUpdateAuthorizationMethod{
		SourceDriftUpdateAccessToken: &sourceDriftUpdateAccessToken,
		Type:                         typ,
	}
}

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

	var sourceDriftUpdateAccessToken SourceDriftUpdateAccessToken = SourceDriftUpdateAccessToken{}
	if err := utils.UnmarshalJSON(data, &sourceDriftUpdateAccessToken, "", true, true); err == nil {
		u.SourceDriftUpdateAccessToken = &sourceDriftUpdateAccessToken
		u.Type = SourceDriftUpdateAuthorizationMethodTypeSourceDriftUpdateAccessToken
		return nil
	}

	var sourceDriftUpdateOAuth20 SourceDriftUpdateOAuth20 = SourceDriftUpdateOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceDriftUpdateOAuth20, "", true, true); err == nil {
		u.SourceDriftUpdateOAuth20 = &sourceDriftUpdateOAuth20
		u.Type = SourceDriftUpdateAuthorizationMethodTypeSourceDriftUpdateOAuth20
		return nil
	}

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

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

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

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

type SourceDriftUpdate struct {
	Credentials *SourceDriftUpdateAuthorizationMethod `json:"credentials,omitempty"`
	// Email used as parameter for contacts stream
	Email *string `default:"test@test.com" json:"email"`
}

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

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

func (o *SourceDriftUpdate) GetCredentials() *SourceDriftUpdateAuthorizationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

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