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

const (
	SourceMondayUpdateSchemasAuthTypeAPIToken SourceMondayUpdateSchemasAuthType = "api_token"
)

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

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

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

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

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

func (o *SourceMondayUpdateAPIToken) GetAuthType() SourceMondayUpdateSchemasAuthType {
	return SourceMondayUpdateSchemasAuthTypeAPIToken
}

type SourceMondayUpdateAuthType string

const (
	SourceMondayUpdateAuthTypeOauth20 SourceMondayUpdateAuthType = "oauth2.0"
)

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

type SourceMondayUpdateOAuth20 struct {
	// Access Token for making authenticated requests.
	AccessToken string                     `json:"access_token"`
	authType    SourceMondayUpdateAuthType `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 SourceMondayUpdateOAuth20) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(s, "", false)
}

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

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

func (o *SourceMondayUpdateOAuth20) GetAuthType() SourceMondayUpdateAuthType {
	return SourceMondayUpdateAuthTypeOauth20
}

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

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

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

type SourceMondayUpdateAuthorizationMethodType string

const (
	SourceMondayUpdateAuthorizationMethodTypeSourceMondayUpdateOAuth20  SourceMondayUpdateAuthorizationMethodType = "source-monday-update_OAuth2.0"
	SourceMondayUpdateAuthorizationMethodTypeSourceMondayUpdateAPIToken SourceMondayUpdateAuthorizationMethodType = "source-monday-update_API Token"
)

type SourceMondayUpdateAuthorizationMethod struct {
	SourceMondayUpdateOAuth20  *SourceMondayUpdateOAuth20  `queryParam:"inline"`
	SourceMondayUpdateAPIToken *SourceMondayUpdateAPIToken `queryParam:"inline"`

	Type SourceMondayUpdateAuthorizationMethodType
}

func CreateSourceMondayUpdateAuthorizationMethodSourceMondayUpdateOAuth20(sourceMondayUpdateOAuth20 SourceMondayUpdateOAuth20) SourceMondayUpdateAuthorizationMethod {
	typ := SourceMondayUpdateAuthorizationMethodTypeSourceMondayUpdateOAuth20

	return SourceMondayUpdateAuthorizationMethod{
		SourceMondayUpdateOAuth20: &sourceMondayUpdateOAuth20,
		Type:                      typ,
	}
}

func CreateSourceMondayUpdateAuthorizationMethodSourceMondayUpdateAPIToken(sourceMondayUpdateAPIToken SourceMondayUpdateAPIToken) SourceMondayUpdateAuthorizationMethod {
	typ := SourceMondayUpdateAuthorizationMethodTypeSourceMondayUpdateAPIToken

	return SourceMondayUpdateAuthorizationMethod{
		SourceMondayUpdateAPIToken: &sourceMondayUpdateAPIToken,
		Type:                       typ,
	}
}

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

	var sourceMondayUpdateAPIToken SourceMondayUpdateAPIToken = SourceMondayUpdateAPIToken{}
	if err := utils.UnmarshalJSON(data, &sourceMondayUpdateAPIToken, "", true, true); err == nil {
		u.SourceMondayUpdateAPIToken = &sourceMondayUpdateAPIToken
		u.Type = SourceMondayUpdateAuthorizationMethodTypeSourceMondayUpdateAPIToken
		return nil
	}

	var sourceMondayUpdateOAuth20 SourceMondayUpdateOAuth20 = SourceMondayUpdateOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceMondayUpdateOAuth20, "", true, true); err == nil {
		u.SourceMondayUpdateOAuth20 = &sourceMondayUpdateOAuth20
		u.Type = SourceMondayUpdateAuthorizationMethodTypeSourceMondayUpdateOAuth20
		return nil
	}

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

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

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

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

type SourceMondayUpdate 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 *SourceMondayUpdateAuthorizationMethod `json:"credentials,omitempty"`
	// The number of worker threads to use for the sync.
	NumWorkers *int64 `default:"4" json:"num_workers"`
}

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

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

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

func (o *SourceMondayUpdate) GetCredentials() *SourceMondayUpdateAuthorizationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

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