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

const (
	SourceMicrosoftTeamsSchemasAuthTypeToken SourceMicrosoftTeamsSchemasAuthType = "Token"
)

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

type AuthenticateViaMicrosoft struct {
	authType *SourceMicrosoftTeamsSchemasAuthType `const:"Token" json:"auth_type"`
	// The Client ID of your Microsoft Teams developer application.
	ClientID string `json:"client_id"`
	// The Client Secret of your Microsoft Teams developer application.
	ClientSecret string `json:"client_secret"`
	// A globally unique identifier (GUID) that is different than your organization name or domain. Follow these steps to obtain: open one of the Teams where you belong inside the Teams Application -> Click on the … next to the Team title -> Click on Get link to team -> Copy the link to the team and grab the tenant ID form the URL
	TenantID string `json:"tenant_id"`
}

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

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

func (o *AuthenticateViaMicrosoft) GetAuthType() *SourceMicrosoftTeamsSchemasAuthType {
	return SourceMicrosoftTeamsSchemasAuthTypeToken.ToPointer()
}

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

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

func (o *AuthenticateViaMicrosoft) GetTenantID() string {
	if o == nil {
		return ""
	}
	return o.TenantID
}

type SourceMicrosoftTeamsAuthType string

const (
	SourceMicrosoftTeamsAuthTypeClient SourceMicrosoftTeamsAuthType = "Client"
)

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

type AuthenticateViaMicrosoftOAuth20 struct {
	authType *SourceMicrosoftTeamsAuthType `const:"Client" json:"auth_type"`
	// The Client ID of your Microsoft Teams developer application.
	ClientID string `json:"client_id"`
	// The Client Secret of your Microsoft Teams developer application.
	ClientSecret string `json:"client_secret"`
	// A Refresh Token to renew the expired Access Token.
	RefreshToken string `json:"refresh_token"`
	// A globally unique identifier (GUID) that is different than your organization name or domain. Follow these steps to obtain: open one of the Teams where you belong inside the Teams Application -> Click on the … next to the Team title -> Click on Get link to team -> Copy the link to the team and grab the tenant ID form the URL
	TenantID string `json:"tenant_id"`
}

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

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

func (o *AuthenticateViaMicrosoftOAuth20) GetAuthType() *SourceMicrosoftTeamsAuthType {
	return SourceMicrosoftTeamsAuthTypeClient.ToPointer()
}

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

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

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

func (o *AuthenticateViaMicrosoftOAuth20) GetTenantID() string {
	if o == nil {
		return ""
	}
	return o.TenantID
}

type SourceMicrosoftTeamsAuthenticationMechanismType string

const (
	SourceMicrosoftTeamsAuthenticationMechanismTypeAuthenticateViaMicrosoftOAuth20 SourceMicrosoftTeamsAuthenticationMechanismType = "Authenticate via Microsoft (OAuth 2.0)"
	SourceMicrosoftTeamsAuthenticationMechanismTypeAuthenticateViaMicrosoft        SourceMicrosoftTeamsAuthenticationMechanismType = "Authenticate via Microsoft"
)

// SourceMicrosoftTeamsAuthenticationMechanism - Choose how to authenticate to Microsoft
type SourceMicrosoftTeamsAuthenticationMechanism struct {
	AuthenticateViaMicrosoftOAuth20 *AuthenticateViaMicrosoftOAuth20 `queryParam:"inline"`
	AuthenticateViaMicrosoft        *AuthenticateViaMicrosoft        `queryParam:"inline"`

	Type SourceMicrosoftTeamsAuthenticationMechanismType
}

func CreateSourceMicrosoftTeamsAuthenticationMechanismAuthenticateViaMicrosoftOAuth20(authenticateViaMicrosoftOAuth20 AuthenticateViaMicrosoftOAuth20) SourceMicrosoftTeamsAuthenticationMechanism {
	typ := SourceMicrosoftTeamsAuthenticationMechanismTypeAuthenticateViaMicrosoftOAuth20

	return SourceMicrosoftTeamsAuthenticationMechanism{
		AuthenticateViaMicrosoftOAuth20: &authenticateViaMicrosoftOAuth20,
		Type:                            typ,
	}
}

func CreateSourceMicrosoftTeamsAuthenticationMechanismAuthenticateViaMicrosoft(authenticateViaMicrosoft AuthenticateViaMicrosoft) SourceMicrosoftTeamsAuthenticationMechanism {
	typ := SourceMicrosoftTeamsAuthenticationMechanismTypeAuthenticateViaMicrosoft

	return SourceMicrosoftTeamsAuthenticationMechanism{
		AuthenticateViaMicrosoft: &authenticateViaMicrosoft,
		Type:                     typ,
	}
}

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

	var authenticateViaMicrosoft AuthenticateViaMicrosoft = AuthenticateViaMicrosoft{}
	if err := utils.UnmarshalJSON(data, &authenticateViaMicrosoft, "", true, true); err == nil {
		u.AuthenticateViaMicrosoft = &authenticateViaMicrosoft
		u.Type = SourceMicrosoftTeamsAuthenticationMechanismTypeAuthenticateViaMicrosoft
		return nil
	}

	var authenticateViaMicrosoftOAuth20 AuthenticateViaMicrosoftOAuth20 = AuthenticateViaMicrosoftOAuth20{}
	if err := utils.UnmarshalJSON(data, &authenticateViaMicrosoftOAuth20, "", true, true); err == nil {
		u.AuthenticateViaMicrosoftOAuth20 = &authenticateViaMicrosoftOAuth20
		u.Type = SourceMicrosoftTeamsAuthenticationMechanismTypeAuthenticateViaMicrosoftOAuth20
		return nil
	}

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

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

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

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

type MicrosoftTeams string

const (
	MicrosoftTeamsMicrosoftTeams MicrosoftTeams = "microsoft-teams"
)

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

type SourceMicrosoftTeams struct {
	// Choose how to authenticate to Microsoft
	Credentials *SourceMicrosoftTeamsAuthenticationMechanism `json:"credentials,omitempty"`
	// Specifies the length of time over which the Team Device Report stream is aggregated. The supported values are: D7, D30, D90, and D180.
	Period     string         `json:"period"`
	sourceType MicrosoftTeams `const:"microsoft-teams" json:"sourceType"`
}

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

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

func (o *SourceMicrosoftTeams) GetCredentials() *SourceMicrosoftTeamsAuthenticationMechanism {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceMicrosoftTeams) GetPeriod() string {
	if o == nil {
		return ""
	}
	return o.Period
}

func (o *SourceMicrosoftTeams) GetSourceType() MicrosoftTeams {
	return MicrosoftTeamsMicrosoftTeams
}
