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

// SourceGoogleDirectoryUpdateSchemasCredentialsTitle - Authentication Scenario
type SourceGoogleDirectoryUpdateSchemasCredentialsTitle string

const (
	SourceGoogleDirectoryUpdateSchemasCredentialsTitleServiceAccounts SourceGoogleDirectoryUpdateSchemasCredentialsTitle = "Service accounts"
)

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

// SourceGoogleDirectoryUpdateServiceAccountKey - For these scenario user should obtain service account's credentials from the Google API Console and provide delegated email.
type SourceGoogleDirectoryUpdateServiceAccountKey struct {
	// The contents of the JSON service account key. See the <a href="https://developers.google.com/admin-sdk/directory/v1/guides/delegation">docs</a> for more information on how to generate this key.
	CredentialsJSON string `json:"credentials_json"`
	// Authentication Scenario
	credentialsTitle *SourceGoogleDirectoryUpdateSchemasCredentialsTitle `const:"Service accounts" json:"credentials_title,omitempty"`
	// The email of the user, which has permissions to access the Google Workspace Admin APIs.
	Email string `json:"email"`
}

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

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

func (o *SourceGoogleDirectoryUpdateServiceAccountKey) GetCredentialsJSON() string {
	if o == nil {
		return ""
	}
	return o.CredentialsJSON
}

func (o *SourceGoogleDirectoryUpdateServiceAccountKey) GetCredentialsTitle() *SourceGoogleDirectoryUpdateSchemasCredentialsTitle {
	return SourceGoogleDirectoryUpdateSchemasCredentialsTitleServiceAccounts.ToPointer()
}

func (o *SourceGoogleDirectoryUpdateServiceAccountKey) GetEmail() string {
	if o == nil {
		return ""
	}
	return o.Email
}

// SourceGoogleDirectoryUpdateCredentialsTitle - Authentication Scenario
type SourceGoogleDirectoryUpdateCredentialsTitle string

const (
	SourceGoogleDirectoryUpdateCredentialsTitleWebServerApp SourceGoogleDirectoryUpdateCredentialsTitle = "Web server app"
)

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

// SourceGoogleDirectoryUpdateSignInViaGoogleOAuth - For these scenario user only needs to give permission to read Google Directory data.
type SourceGoogleDirectoryUpdateSignInViaGoogleOAuth struct {
	// The Client ID of the developer application.
	ClientID string `json:"client_id"`
	// The Client Secret of the developer application.
	ClientSecret string `json:"client_secret"`
	// Authentication Scenario
	credentialsTitle *SourceGoogleDirectoryUpdateCredentialsTitle `const:"Web server app" json:"credentials_title,omitempty"`
	// The Token for obtaining a new access token.
	RefreshToken string `json:"refresh_token"`
}

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

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

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

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

func (o *SourceGoogleDirectoryUpdateSignInViaGoogleOAuth) GetCredentialsTitle() *SourceGoogleDirectoryUpdateCredentialsTitle {
	return SourceGoogleDirectoryUpdateCredentialsTitleWebServerApp.ToPointer()
}

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

type SourceGoogleDirectoryUpdateGoogleCredentialsType string

const (
	SourceGoogleDirectoryUpdateGoogleCredentialsTypeSourceGoogleDirectoryUpdateSignInViaGoogleOAuth SourceGoogleDirectoryUpdateGoogleCredentialsType = "source-google-directory-update_Sign in via Google (OAuth)"
	SourceGoogleDirectoryUpdateGoogleCredentialsTypeSourceGoogleDirectoryUpdateServiceAccountKey    SourceGoogleDirectoryUpdateGoogleCredentialsType = "source-google-directory-update_Service Account Key"
)

// SourceGoogleDirectoryUpdateGoogleCredentials - Google APIs use the OAuth 2.0 protocol for authentication and authorization. The Source supports <a href="https://developers.google.com/identity/protocols/oauth2#webserver" target="_blank">Web server application</a> and <a href="https://developers.google.com/identity/protocols/oauth2#serviceaccount" target="_blank">Service accounts</a> scenarios.
type SourceGoogleDirectoryUpdateGoogleCredentials struct {
	SourceGoogleDirectoryUpdateSignInViaGoogleOAuth *SourceGoogleDirectoryUpdateSignInViaGoogleOAuth `queryParam:"inline"`
	SourceGoogleDirectoryUpdateServiceAccountKey    *SourceGoogleDirectoryUpdateServiceAccountKey    `queryParam:"inline"`

	Type SourceGoogleDirectoryUpdateGoogleCredentialsType
}

func CreateSourceGoogleDirectoryUpdateGoogleCredentialsSourceGoogleDirectoryUpdateSignInViaGoogleOAuth(sourceGoogleDirectoryUpdateSignInViaGoogleOAuth SourceGoogleDirectoryUpdateSignInViaGoogleOAuth) SourceGoogleDirectoryUpdateGoogleCredentials {
	typ := SourceGoogleDirectoryUpdateGoogleCredentialsTypeSourceGoogleDirectoryUpdateSignInViaGoogleOAuth

	return SourceGoogleDirectoryUpdateGoogleCredentials{
		SourceGoogleDirectoryUpdateSignInViaGoogleOAuth: &sourceGoogleDirectoryUpdateSignInViaGoogleOAuth,
		Type: typ,
	}
}

func CreateSourceGoogleDirectoryUpdateGoogleCredentialsSourceGoogleDirectoryUpdateServiceAccountKey(sourceGoogleDirectoryUpdateServiceAccountKey SourceGoogleDirectoryUpdateServiceAccountKey) SourceGoogleDirectoryUpdateGoogleCredentials {
	typ := SourceGoogleDirectoryUpdateGoogleCredentialsTypeSourceGoogleDirectoryUpdateServiceAccountKey

	return SourceGoogleDirectoryUpdateGoogleCredentials{
		SourceGoogleDirectoryUpdateServiceAccountKey: &sourceGoogleDirectoryUpdateServiceAccountKey,
		Type: typ,
	}
}

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

	var sourceGoogleDirectoryUpdateServiceAccountKey SourceGoogleDirectoryUpdateServiceAccountKey = SourceGoogleDirectoryUpdateServiceAccountKey{}
	if err := utils.UnmarshalJSON(data, &sourceGoogleDirectoryUpdateServiceAccountKey, "", true, true); err == nil {
		u.SourceGoogleDirectoryUpdateServiceAccountKey = &sourceGoogleDirectoryUpdateServiceAccountKey
		u.Type = SourceGoogleDirectoryUpdateGoogleCredentialsTypeSourceGoogleDirectoryUpdateServiceAccountKey
		return nil
	}

	var sourceGoogleDirectoryUpdateSignInViaGoogleOAuth SourceGoogleDirectoryUpdateSignInViaGoogleOAuth = SourceGoogleDirectoryUpdateSignInViaGoogleOAuth{}
	if err := utils.UnmarshalJSON(data, &sourceGoogleDirectoryUpdateSignInViaGoogleOAuth, "", true, true); err == nil {
		u.SourceGoogleDirectoryUpdateSignInViaGoogleOAuth = &sourceGoogleDirectoryUpdateSignInViaGoogleOAuth
		u.Type = SourceGoogleDirectoryUpdateGoogleCredentialsTypeSourceGoogleDirectoryUpdateSignInViaGoogleOAuth
		return nil
	}

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

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

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

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

type SourceGoogleDirectoryUpdate struct {
	// Google APIs use the OAuth 2.0 protocol for authentication and authorization. The Source supports <a href="https://developers.google.com/identity/protocols/oauth2#webserver" target="_blank">Web server application</a> and <a href="https://developers.google.com/identity/protocols/oauth2#serviceaccount" target="_blank">Service accounts</a> scenarios.
	Credentials *SourceGoogleDirectoryUpdateGoogleCredentials `json:"credentials,omitempty"`
}

func (o *SourceGoogleDirectoryUpdate) GetCredentials() *SourceGoogleDirectoryUpdateGoogleCredentials {
	if o == nil {
		return nil
	}
	return o.Credentials
}
