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

type SourceNotionUpdateSchemasAuthType string

const (
	SourceNotionUpdateSchemasAuthTypeToken SourceNotionUpdateSchemasAuthType = "token"
)

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

type SourceNotionUpdateAccessToken struct {
	authType SourceNotionUpdateSchemasAuthType `const:"token" json:"auth_type"`
	// The Access Token for your private Notion integration. See the <a href='https://docs.airbyte.com/integrations/sources/notion#step-1-create-an-integration-in-notion'>docs</a> for more information on how to obtain this token.
	Token string `json:"token"`
}

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

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

func (o *SourceNotionUpdateAccessToken) GetAuthType() SourceNotionUpdateSchemasAuthType {
	return SourceNotionUpdateSchemasAuthTypeToken
}

func (o *SourceNotionUpdateAccessToken) GetToken() string {
	if o == nil {
		return ""
	}
	return o.Token
}

type SourceNotionUpdateAuthType string

const (
	SourceNotionUpdateAuthTypeOAuth20 SourceNotionUpdateAuthType = "OAuth2.0"
)

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

type SourceNotionUpdateOAuth20 struct {
	// The Access Token received by completing the OAuth flow for your Notion integration. See our <a href='https://docs.airbyte.com/integrations/sources/notion#step-2-set-permissions-and-acquire-authorization-credentials'>docs</a> for more information.
	AccessToken string                     `json:"access_token"`
	authType    SourceNotionUpdateAuthType `const:"OAuth2.0" json:"auth_type"`
	// The Client ID of your Notion integration. See our <a href='https://docs.airbyte.com/integrations/sources/notion#step-2-set-permissions-and-acquire-authorization-credentials'>docs</a> for more information.
	ClientID string `json:"client_id"`
	// The Client Secret of your Notion integration. See our <a href='https://docs.airbyte.com/integrations/sources/notion#step-2-set-permissions-and-acquire-authorization-credentials'>docs</a> for more information.
	ClientSecret string `json:"client_secret"`
}

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

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

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

func (o *SourceNotionUpdateOAuth20) GetAuthType() SourceNotionUpdateAuthType {
	return SourceNotionUpdateAuthTypeOAuth20
}

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

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

type SourceNotionUpdateAuthenticationMethodType string

const (
	SourceNotionUpdateAuthenticationMethodTypeSourceNotionUpdateOAuth20     SourceNotionUpdateAuthenticationMethodType = "source-notion-update_OAuth2.0"
	SourceNotionUpdateAuthenticationMethodTypeSourceNotionUpdateAccessToken SourceNotionUpdateAuthenticationMethodType = "source-notion-update_Access Token"
)

// SourceNotionUpdateAuthenticationMethod - Choose either OAuth (recommended for Airbyte Cloud) or Access Token. See our <a href='https://docs.airbyte.com/integrations/sources/notion#setup-guide'>docs</a> for more information.
type SourceNotionUpdateAuthenticationMethod struct {
	SourceNotionUpdateOAuth20     *SourceNotionUpdateOAuth20     `queryParam:"inline"`
	SourceNotionUpdateAccessToken *SourceNotionUpdateAccessToken `queryParam:"inline"`

	Type SourceNotionUpdateAuthenticationMethodType
}

func CreateSourceNotionUpdateAuthenticationMethodSourceNotionUpdateOAuth20(sourceNotionUpdateOAuth20 SourceNotionUpdateOAuth20) SourceNotionUpdateAuthenticationMethod {
	typ := SourceNotionUpdateAuthenticationMethodTypeSourceNotionUpdateOAuth20

	return SourceNotionUpdateAuthenticationMethod{
		SourceNotionUpdateOAuth20: &sourceNotionUpdateOAuth20,
		Type:                      typ,
	}
}

func CreateSourceNotionUpdateAuthenticationMethodSourceNotionUpdateAccessToken(sourceNotionUpdateAccessToken SourceNotionUpdateAccessToken) SourceNotionUpdateAuthenticationMethod {
	typ := SourceNotionUpdateAuthenticationMethodTypeSourceNotionUpdateAccessToken

	return SourceNotionUpdateAuthenticationMethod{
		SourceNotionUpdateAccessToken: &sourceNotionUpdateAccessToken,
		Type:                          typ,
	}
}

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

	var sourceNotionUpdateAccessToken SourceNotionUpdateAccessToken = SourceNotionUpdateAccessToken{}
	if err := utils.UnmarshalJSON(data, &sourceNotionUpdateAccessToken, "", true, true); err == nil {
		u.SourceNotionUpdateAccessToken = &sourceNotionUpdateAccessToken
		u.Type = SourceNotionUpdateAuthenticationMethodTypeSourceNotionUpdateAccessToken
		return nil
	}

	var sourceNotionUpdateOAuth20 SourceNotionUpdateOAuth20 = SourceNotionUpdateOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceNotionUpdateOAuth20, "", true, true); err == nil {
		u.SourceNotionUpdateOAuth20 = &sourceNotionUpdateOAuth20
		u.Type = SourceNotionUpdateAuthenticationMethodTypeSourceNotionUpdateOAuth20
		return nil
	}

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

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

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

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

type SourceNotionUpdate struct {
	// Choose either OAuth (recommended for Airbyte Cloud) or Access Token. See our <a href='https://docs.airbyte.com/integrations/sources/notion#setup-guide'>docs</a> for more information.
	Credentials *SourceNotionUpdateAuthenticationMethod `json:"credentials,omitempty"`
	// UTC date and time in the format YYYY-MM-DDTHH:MM:SS.000Z. During incremental sync, any data generated before this date will not be replicated. If left blank, the start date will be set to 2 years before the present date.
	StartDate *time.Time `json:"start_date,omitempty"`
}

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

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

func (o *SourceNotionUpdate) GetCredentials() *SourceNotionUpdateAuthenticationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceNotionUpdate) GetStartDate() *time.Time {
	if o == nil {
		return nil
	}
	return o.StartDate
}
