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

// SourceAsanaUpdateSchemasCredentialsTitle - PAT Credentials
type SourceAsanaUpdateSchemasCredentialsTitle string

const (
	SourceAsanaUpdateSchemasCredentialsTitlePatCredentials SourceAsanaUpdateSchemasCredentialsTitle = "PAT Credentials"
)

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

type SourceAsanaUpdateAuthenticateWithPersonalAccessToken struct {
	// PAT Credentials
	optionTitle *SourceAsanaUpdateSchemasCredentialsTitle `const:"PAT Credentials" json:"option_title,omitempty"`
	// Asana Personal Access Token (generate yours <a href="https://app.asana.com/0/developer-console">here</a>).
	PersonalAccessToken string `json:"personal_access_token"`
}

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

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

func (o *SourceAsanaUpdateAuthenticateWithPersonalAccessToken) GetOptionTitle() *SourceAsanaUpdateSchemasCredentialsTitle {
	return SourceAsanaUpdateSchemasCredentialsTitlePatCredentials.ToPointer()
}

func (o *SourceAsanaUpdateAuthenticateWithPersonalAccessToken) GetPersonalAccessToken() string {
	if o == nil {
		return ""
	}
	return o.PersonalAccessToken
}

// SourceAsanaUpdateCredentialsTitle - OAuth Credentials
type SourceAsanaUpdateCredentialsTitle string

const (
	SourceAsanaUpdateCredentialsTitleOAuthCredentials SourceAsanaUpdateCredentialsTitle = "OAuth Credentials"
)

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

type SourceAsanaUpdateAuthenticateViaAsanaOauth struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	// OAuth Credentials
	optionTitle  *SourceAsanaUpdateCredentialsTitle `const:"OAuth Credentials" json:"option_title,omitempty"`
	RefreshToken string                             `json:"refresh_token"`
}

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

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

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

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

func (o *SourceAsanaUpdateAuthenticateViaAsanaOauth) GetOptionTitle() *SourceAsanaUpdateCredentialsTitle {
	return SourceAsanaUpdateCredentialsTitleOAuthCredentials.ToPointer()
}

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

type SourceAsanaUpdateAuthenticationMechanismType string

const (
	SourceAsanaUpdateAuthenticationMechanismTypeSourceAsanaUpdateAuthenticateViaAsanaOauth           SourceAsanaUpdateAuthenticationMechanismType = "source-asana-update_Authenticate via Asana (Oauth)"
	SourceAsanaUpdateAuthenticationMechanismTypeSourceAsanaUpdateAuthenticateWithPersonalAccessToken SourceAsanaUpdateAuthenticationMechanismType = "source-asana-update_Authenticate with Personal Access Token"
)

// SourceAsanaUpdateAuthenticationMechanism - Choose how to authenticate to Github
type SourceAsanaUpdateAuthenticationMechanism struct {
	SourceAsanaUpdateAuthenticateViaAsanaOauth           *SourceAsanaUpdateAuthenticateViaAsanaOauth           `queryParam:"inline"`
	SourceAsanaUpdateAuthenticateWithPersonalAccessToken *SourceAsanaUpdateAuthenticateWithPersonalAccessToken `queryParam:"inline"`

	Type SourceAsanaUpdateAuthenticationMechanismType
}

func CreateSourceAsanaUpdateAuthenticationMechanismSourceAsanaUpdateAuthenticateViaAsanaOauth(sourceAsanaUpdateAuthenticateViaAsanaOauth SourceAsanaUpdateAuthenticateViaAsanaOauth) SourceAsanaUpdateAuthenticationMechanism {
	typ := SourceAsanaUpdateAuthenticationMechanismTypeSourceAsanaUpdateAuthenticateViaAsanaOauth

	return SourceAsanaUpdateAuthenticationMechanism{
		SourceAsanaUpdateAuthenticateViaAsanaOauth: &sourceAsanaUpdateAuthenticateViaAsanaOauth,
		Type: typ,
	}
}

func CreateSourceAsanaUpdateAuthenticationMechanismSourceAsanaUpdateAuthenticateWithPersonalAccessToken(sourceAsanaUpdateAuthenticateWithPersonalAccessToken SourceAsanaUpdateAuthenticateWithPersonalAccessToken) SourceAsanaUpdateAuthenticationMechanism {
	typ := SourceAsanaUpdateAuthenticationMechanismTypeSourceAsanaUpdateAuthenticateWithPersonalAccessToken

	return SourceAsanaUpdateAuthenticationMechanism{
		SourceAsanaUpdateAuthenticateWithPersonalAccessToken: &sourceAsanaUpdateAuthenticateWithPersonalAccessToken,
		Type: typ,
	}
}

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

	var sourceAsanaUpdateAuthenticateWithPersonalAccessToken SourceAsanaUpdateAuthenticateWithPersonalAccessToken = SourceAsanaUpdateAuthenticateWithPersonalAccessToken{}
	if err := utils.UnmarshalJSON(data, &sourceAsanaUpdateAuthenticateWithPersonalAccessToken, "", true, true); err == nil {
		u.SourceAsanaUpdateAuthenticateWithPersonalAccessToken = &sourceAsanaUpdateAuthenticateWithPersonalAccessToken
		u.Type = SourceAsanaUpdateAuthenticationMechanismTypeSourceAsanaUpdateAuthenticateWithPersonalAccessToken
		return nil
	}

	var sourceAsanaUpdateAuthenticateViaAsanaOauth SourceAsanaUpdateAuthenticateViaAsanaOauth = SourceAsanaUpdateAuthenticateViaAsanaOauth{}
	if err := utils.UnmarshalJSON(data, &sourceAsanaUpdateAuthenticateViaAsanaOauth, "", true, true); err == nil {
		u.SourceAsanaUpdateAuthenticateViaAsanaOauth = &sourceAsanaUpdateAuthenticateViaAsanaOauth
		u.Type = SourceAsanaUpdateAuthenticationMechanismTypeSourceAsanaUpdateAuthenticateViaAsanaOauth
		return nil
	}

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

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

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

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

type SourceAsanaUpdate struct {
	// Choose how to authenticate to Github
	Credentials *SourceAsanaUpdateAuthenticationMechanism `json:"credentials,omitempty"`
	// The number of worker threads to use for the sync. The performance upper boundary is based on the limit of your Asana pricing plan. More info about the rate limit tiers can be found on Asana's API <a href="https://developers.asana.com/docs/rate-limits">docs</a>.
	NumWorkers *int64 `default:"10" json:"num_workers"`
	// Globally unique identifiers for the organization exports
	OrganizationExportIds []any `json:"organization_export_ids,omitempty"`
}

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

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

func (o *SourceAsanaUpdate) GetCredentials() *SourceAsanaUpdateAuthenticationMechanism {
	if o == nil {
		return nil
	}
	return o.Credentials
}

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

func (o *SourceAsanaUpdate) GetOrganizationExportIds() []any {
	if o == nil {
		return nil
	}
	return o.OrganizationExportIds
}
