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

const (
	SourceMicrosoftTeamsUpdateSchemasAuthTypeToken SourceMicrosoftTeamsUpdateSchemasAuthType = "Token"
)

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

type SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft struct {
	authType *SourceMicrosoftTeamsUpdateSchemasAuthType `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 (s SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(s, "", false)
}

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

func (o *SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft) GetAuthType() *SourceMicrosoftTeamsUpdateSchemasAuthType {
	return SourceMicrosoftTeamsUpdateSchemasAuthTypeToken.ToPointer()
}

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

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

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

type SourceMicrosoftTeamsUpdateAuthType string

const (
	SourceMicrosoftTeamsUpdateAuthTypeClient SourceMicrosoftTeamsUpdateAuthType = "Client"
)

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

type SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20 struct {
	authType *SourceMicrosoftTeamsUpdateAuthType `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 (s SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20) MarshalJSON() ([]byte, error) {
	return utils.MarshalJSON(s, "", false)
}

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

func (o *SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20) GetAuthType() *SourceMicrosoftTeamsUpdateAuthType {
	return SourceMicrosoftTeamsUpdateAuthTypeClient.ToPointer()
}

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

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

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

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

type SourceMicrosoftTeamsUpdateAuthenticationMechanismType string

const (
	SourceMicrosoftTeamsUpdateAuthenticationMechanismTypeSourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20 SourceMicrosoftTeamsUpdateAuthenticationMechanismType = "source-microsoft-teams-update_Authenticate via Microsoft (OAuth 2.0)"
	SourceMicrosoftTeamsUpdateAuthenticationMechanismTypeSourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft        SourceMicrosoftTeamsUpdateAuthenticationMechanismType = "source-microsoft-teams-update_Authenticate via Microsoft"
)

// SourceMicrosoftTeamsUpdateAuthenticationMechanism - Choose how to authenticate to Microsoft
type SourceMicrosoftTeamsUpdateAuthenticationMechanism struct {
	SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20 *SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20 `queryParam:"inline"`
	SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft        *SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft        `queryParam:"inline"`

	Type SourceMicrosoftTeamsUpdateAuthenticationMechanismType
}

func CreateSourceMicrosoftTeamsUpdateAuthenticationMechanismSourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20(sourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20 SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20) SourceMicrosoftTeamsUpdateAuthenticationMechanism {
	typ := SourceMicrosoftTeamsUpdateAuthenticationMechanismTypeSourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20

	return SourceMicrosoftTeamsUpdateAuthenticationMechanism{
		SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20: &sourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20,
		Type: typ,
	}
}

func CreateSourceMicrosoftTeamsUpdateAuthenticationMechanismSourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft(sourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft) SourceMicrosoftTeamsUpdateAuthenticationMechanism {
	typ := SourceMicrosoftTeamsUpdateAuthenticationMechanismTypeSourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft

	return SourceMicrosoftTeamsUpdateAuthenticationMechanism{
		SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft: &sourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft,
		Type: typ,
	}
}

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

	var sourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft = SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft{}
	if err := utils.UnmarshalJSON(data, &sourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft, "", true, true); err == nil {
		u.SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft = &sourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft
		u.Type = SourceMicrosoftTeamsUpdateAuthenticationMechanismTypeSourceMicrosoftTeamsUpdateAuthenticateViaMicrosoft
		return nil
	}

	var sourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20 SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20 = SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20, "", true, true); err == nil {
		u.SourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20 = &sourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20
		u.Type = SourceMicrosoftTeamsUpdateAuthenticationMechanismTypeSourceMicrosoftTeamsUpdateAuthenticateViaMicrosoftOAuth20
		return nil
	}

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

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

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

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

type SourceMicrosoftTeamsUpdate struct {
	// Choose how to authenticate to Microsoft
	Credentials *SourceMicrosoftTeamsUpdateAuthenticationMechanism `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"`
}

func (o *SourceMicrosoftTeamsUpdate) GetCredentials() *SourceMicrosoftTeamsUpdateAuthenticationMechanism {
	if o == nil {
		return nil
	}
	return o.Credentials
}

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