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

const (
	SourceNotionSchemasAuthTypeToken SourceNotionSchemasAuthType = "token"
)

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

type SourceNotionAccessToken struct {
	authType SourceNotionSchemasAuthType `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 SourceNotionAccessToken) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(s, "", false)
}

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

func (o *SourceNotionAccessToken) GetAuthType() SourceNotionSchemasAuthType {
	return SourceNotionSchemasAuthTypeToken
}

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

type SourceNotionAuthType string

const (
	SourceNotionAuthTypeOAuth20 SourceNotionAuthType = "OAuth2.0"
)

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

type SourceNotionOAuth20 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    SourceNotionAuthType `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 SourceNotionOAuth20) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(s, "", false)
}

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

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

func (o *SourceNotionOAuth20) GetAuthType() SourceNotionAuthType {
	return SourceNotionAuthTypeOAuth20
}

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

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

type SourceNotionAuthenticationMethodType string

const (
	SourceNotionAuthenticationMethodTypeSourceNotionOAuth20     SourceNotionAuthenticationMethodType = "source-notion_OAuth2.0"
	SourceNotionAuthenticationMethodTypeSourceNotionAccessToken SourceNotionAuthenticationMethodType = "source-notion_Access Token"
)

// SourceNotionAuthenticationMethod - 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 SourceNotionAuthenticationMethod struct {
	SourceNotionOAuth20     *SourceNotionOAuth20     `queryParam:"inline"`
	SourceNotionAccessToken *SourceNotionAccessToken `queryParam:"inline"`

	Type SourceNotionAuthenticationMethodType
}

func CreateSourceNotionAuthenticationMethodSourceNotionOAuth20(sourceNotionOAuth20 SourceNotionOAuth20) SourceNotionAuthenticationMethod {
	typ := SourceNotionAuthenticationMethodTypeSourceNotionOAuth20

	return SourceNotionAuthenticationMethod{
		SourceNotionOAuth20: &sourceNotionOAuth20,
		Type:                typ,
	}
}

func CreateSourceNotionAuthenticationMethodSourceNotionAccessToken(sourceNotionAccessToken SourceNotionAccessToken) SourceNotionAuthenticationMethod {
	typ := SourceNotionAuthenticationMethodTypeSourceNotionAccessToken

	return SourceNotionAuthenticationMethod{
		SourceNotionAccessToken: &sourceNotionAccessToken,
		Type:                    typ,
	}
}

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

	var sourceNotionAccessToken SourceNotionAccessToken = SourceNotionAccessToken{}
	if err := utils.UnmarshalJSON(data, &sourceNotionAccessToken, "", true, true); err == nil {
		u.SourceNotionAccessToken = &sourceNotionAccessToken
		u.Type = SourceNotionAuthenticationMethodTypeSourceNotionAccessToken
		return nil
	}

	var sourceNotionOAuth20 SourceNotionOAuth20 = SourceNotionOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceNotionOAuth20, "", true, true); err == nil {
		u.SourceNotionOAuth20 = &sourceNotionOAuth20
		u.Type = SourceNotionAuthenticationMethodTypeSourceNotionOAuth20
		return nil
	}

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

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

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

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

type Notion string

const (
	NotionNotion Notion = "notion"
)

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

type SourceNotion 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 *SourceNotionAuthenticationMethod `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"`
	sourceType *Notion    `const:"notion" json:"sourceType,omitempty"`
}

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

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

func (o *SourceNotion) GetCredentials() *SourceNotionAuthenticationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

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

func (o *SourceNotion) GetSourceType() *Notion {
	return NotionNotion.ToPointer()
}
