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

const (
	SourceMondaySchemasAuthTypeAPIToken SourceMondaySchemasAuthType = "api_token"
)

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

type APIToken struct {
	// API Token for making authenticated requests.
	APIToken string                      `json:"api_token"`
	authType SourceMondaySchemasAuthType `const:"api_token" json:"auth_type"`
}

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

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

func (o *APIToken) GetAPIToken() string {
	if o == nil {
		return ""
	}
	return o.APIToken
}

func (o *APIToken) GetAuthType() SourceMondaySchemasAuthType {
	return SourceMondaySchemasAuthTypeAPIToken
}

type SourceMondayAuthType string

const (
	SourceMondayAuthTypeOauth20 SourceMondayAuthType = "oauth2.0"
)

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

type SourceMondayOAuth20 struct {
	// Access Token for making authenticated requests.
	AccessToken string               `json:"access_token"`
	authType    SourceMondayAuthType `const:"oauth2.0" json:"auth_type"`
	// The Client ID of your OAuth application.
	ClientID string `json:"client_id"`
	// The Client Secret of your OAuth application.
	ClientSecret string `json:"client_secret"`
	// Slug/subdomain of the account, or the first part of the URL that comes before .monday.com
	Subdomain *string `default:"" json:"subdomain"`
}

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

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

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

func (o *SourceMondayOAuth20) GetAuthType() SourceMondayAuthType {
	return SourceMondayAuthTypeOauth20
}

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

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

func (o *SourceMondayOAuth20) GetSubdomain() *string {
	if o == nil {
		return nil
	}
	return o.Subdomain
}

type SourceMondayAuthorizationMethodType string

const (
	SourceMondayAuthorizationMethodTypeSourceMondayOAuth20 SourceMondayAuthorizationMethodType = "source-monday_OAuth2.0"
	SourceMondayAuthorizationMethodTypeAPIToken            SourceMondayAuthorizationMethodType = "API Token"
)

type SourceMondayAuthorizationMethod struct {
	SourceMondayOAuth20 *SourceMondayOAuth20 `queryParam:"inline"`
	APIToken            *APIToken            `queryParam:"inline"`

	Type SourceMondayAuthorizationMethodType
}

func CreateSourceMondayAuthorizationMethodSourceMondayOAuth20(sourceMondayOAuth20 SourceMondayOAuth20) SourceMondayAuthorizationMethod {
	typ := SourceMondayAuthorizationMethodTypeSourceMondayOAuth20

	return SourceMondayAuthorizationMethod{
		SourceMondayOAuth20: &sourceMondayOAuth20,
		Type:                typ,
	}
}

func CreateSourceMondayAuthorizationMethodAPIToken(apiToken APIToken) SourceMondayAuthorizationMethod {
	typ := SourceMondayAuthorizationMethodTypeAPIToken

	return SourceMondayAuthorizationMethod{
		APIToken: &apiToken,
		Type:     typ,
	}
}

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

	var apiToken APIToken = APIToken{}
	if err := utils.UnmarshalJSON(data, &apiToken, "", true, true); err == nil {
		u.APIToken = &apiToken
		u.Type = SourceMondayAuthorizationMethodTypeAPIToken
		return nil
	}

	var sourceMondayOAuth20 SourceMondayOAuth20 = SourceMondayOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceMondayOAuth20, "", true, true); err == nil {
		u.SourceMondayOAuth20 = &sourceMondayOAuth20
		u.Type = SourceMondayAuthorizationMethodTypeSourceMondayOAuth20
		return nil
	}

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

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

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

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

type Monday string

const (
	MondayMonday Monday = "monday"
)

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

type SourceMonday struct {
	// The IDs of the boards that the Items and Boards streams will extract records from. When left empty, streams will extract records from all boards that exist within the account.
	BoardIds    []int64                          `json:"board_ids,omitempty"`
	Credentials *SourceMondayAuthorizationMethod `json:"credentials,omitempty"`
	// The number of worker threads to use for the sync.
	NumWorkers *int64 `default:"4" json:"num_workers"`
	sourceType Monday `const:"monday" json:"sourceType"`
}

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

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

func (o *SourceMonday) GetBoardIds() []int64 {
	if o == nil {
		return nil
	}
	return o.BoardIds
}

func (o *SourceMonday) GetCredentials() *SourceMondayAuthorizationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceMonday) GetNumWorkers() *int64 {
	if o == nil {
		return nil
	}
	return o.NumWorkers
}

func (o *SourceMonday) GetSourceType() Monday {
	return MondayMonday
}
