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

// SourceAsanaCredentialsTitle - PAT Credentials
type SourceAsanaCredentialsTitle string

const (
	SourceAsanaCredentialsTitlePatCredentials SourceAsanaCredentialsTitle = "PAT Credentials"
)

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

type AuthenticateWithPersonalAccessToken struct {
	// PAT Credentials
	optionTitle *SourceAsanaCredentialsTitle `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 (a AuthenticateWithPersonalAccessToken) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(a, "", false)
}

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

func (o *AuthenticateWithPersonalAccessToken) GetOptionTitle() *SourceAsanaCredentialsTitle {
	return SourceAsanaCredentialsTitlePatCredentials.ToPointer()
}

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

// CredentialsTitle - OAuth Credentials
type CredentialsTitle string

const (
	CredentialsTitleOAuthCredentials CredentialsTitle = "OAuth Credentials"
)

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

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

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

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

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

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

func (o *AuthenticateViaAsanaOauth) GetOptionTitle() *CredentialsTitle {
	return CredentialsTitleOAuthCredentials.ToPointer()
}

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

type AuthenticationMechanismType string

const (
	AuthenticationMechanismTypeAuthenticateViaAsanaOauth           AuthenticationMechanismType = "Authenticate via Asana (Oauth)"
	AuthenticationMechanismTypeAuthenticateWithPersonalAccessToken AuthenticationMechanismType = "Authenticate with Personal Access Token"
)

// AuthenticationMechanism - Choose how to authenticate to Github
type AuthenticationMechanism struct {
	AuthenticateViaAsanaOauth           *AuthenticateViaAsanaOauth           `queryParam:"inline"`
	AuthenticateWithPersonalAccessToken *AuthenticateWithPersonalAccessToken `queryParam:"inline"`

	Type AuthenticationMechanismType
}

func CreateAuthenticationMechanismAuthenticateViaAsanaOauth(authenticateViaAsanaOauth AuthenticateViaAsanaOauth) AuthenticationMechanism {
	typ := AuthenticationMechanismTypeAuthenticateViaAsanaOauth

	return AuthenticationMechanism{
		AuthenticateViaAsanaOauth: &authenticateViaAsanaOauth,
		Type:                      typ,
	}
}

func CreateAuthenticationMechanismAuthenticateWithPersonalAccessToken(authenticateWithPersonalAccessToken AuthenticateWithPersonalAccessToken) AuthenticationMechanism {
	typ := AuthenticationMechanismTypeAuthenticateWithPersonalAccessToken

	return AuthenticationMechanism{
		AuthenticateWithPersonalAccessToken: &authenticateWithPersonalAccessToken,
		Type:                                typ,
	}
}

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

	var authenticateWithPersonalAccessToken AuthenticateWithPersonalAccessToken = AuthenticateWithPersonalAccessToken{}
	if err := utils.UnmarshalJSON(data, &authenticateWithPersonalAccessToken, "", true, true); err == nil {
		u.AuthenticateWithPersonalAccessToken = &authenticateWithPersonalAccessToken
		u.Type = AuthenticationMechanismTypeAuthenticateWithPersonalAccessToken
		return nil
	}

	var authenticateViaAsanaOauth AuthenticateViaAsanaOauth = AuthenticateViaAsanaOauth{}
	if err := utils.UnmarshalJSON(data, &authenticateViaAsanaOauth, "", true, true); err == nil {
		u.AuthenticateViaAsanaOauth = &authenticateViaAsanaOauth
		u.Type = AuthenticationMechanismTypeAuthenticateViaAsanaOauth
		return nil
	}

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

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

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

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

type Asana string

const (
	AsanaAsana Asana = "asana"
)

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

type SourceAsana struct {
	// Choose how to authenticate to Github
	Credentials *AuthenticationMechanism `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"`
	sourceType            *Asana `const:"asana" json:"sourceType,omitempty"`
}

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

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

func (o *SourceAsana) GetCredentials() *AuthenticationMechanism {
	if o == nil {
		return nil
	}
	return o.Credentials
}

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

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

func (o *SourceAsana) GetSourceType() *Asana {
	return AsanaAsana.ToPointer()
}
