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

type SourceOktaUpdateSchemasCredentialsAuthType string

const (
	SourceOktaUpdateSchemasCredentialsAuthTypeAPIToken SourceOktaUpdateSchemasCredentialsAuthType = "api_token"
)

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

type SourceOktaUpdateAPIToken struct {
	// An Okta token. See the <a href="https://docs.airbyte.com/integrations/sources/okta">docs</a> for instructions on how to generate it.
	APIToken string                                     `json:"api_token"`
	authType SourceOktaUpdateSchemasCredentialsAuthType `const:"api_token" json:"auth_type"`
}

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

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

func (o *SourceOktaUpdateAPIToken) GetAPIToken() string {
	if o == nil {
		return ""
	}
	return o.APIToken
}

func (o *SourceOktaUpdateAPIToken) GetAuthType() SourceOktaUpdateSchemasCredentialsAuthType {
	return SourceOktaUpdateSchemasCredentialsAuthTypeAPIToken
}

type SourceOktaUpdateSchemasAuthType string

const (
	SourceOktaUpdateSchemasAuthTypeOauth20PrivateKey SourceOktaUpdateSchemasAuthType = "oauth2.0_private_key"
)

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

type SourceOktaUpdateOAuth20WithPrivateKey struct {
	authType SourceOktaUpdateSchemasAuthType `const:"oauth2.0_private_key" json:"auth_type"`
	// The Client ID of your OAuth application.
	ClientID string `json:"client_id"`
	// The key ID (kid).
	KeyID string `json:"key_id"`
	// The private key in PEM format
	PrivateKey string `json:"private_key"`
	// The OAuth scope.
	Scope string `json:"scope"`
}

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

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

func (o *SourceOktaUpdateOAuth20WithPrivateKey) GetAuthType() SourceOktaUpdateSchemasAuthType {
	return SourceOktaUpdateSchemasAuthTypeOauth20PrivateKey
}

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

func (o *SourceOktaUpdateOAuth20WithPrivateKey) GetKeyID() string {
	if o == nil {
		return ""
	}
	return o.KeyID
}

func (o *SourceOktaUpdateOAuth20WithPrivateKey) GetPrivateKey() string {
	if o == nil {
		return ""
	}
	return o.PrivateKey
}

func (o *SourceOktaUpdateOAuth20WithPrivateKey) GetScope() string {
	if o == nil {
		return ""
	}
	return o.Scope
}

type SourceOktaUpdateAuthType string

const (
	SourceOktaUpdateAuthTypeOauth20 SourceOktaUpdateAuthType = "oauth2.0"
)

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

type SourceOktaUpdateOAuth20 struct {
	authType SourceOktaUpdateAuthType `const:"oauth2.0" json:"auth_type"`
	// The Client ID of your OAuth application.
	ClientID string `json:"client_id"`
	// The Client Secret of your OAuth application.
	ClientSecret string `json:"client_secret"`
	// Refresh Token to obtain new Access Token, when it's expired.
	RefreshToken string `json:"refresh_token"`
}

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

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

func (o *SourceOktaUpdateOAuth20) GetAuthType() SourceOktaUpdateAuthType {
	return SourceOktaUpdateAuthTypeOauth20
}

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

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

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

type SourceOktaUpdateAuthorizationMethodType string

const (
	SourceOktaUpdateAuthorizationMethodTypeSourceOktaUpdateOAuth20               SourceOktaUpdateAuthorizationMethodType = "source-okta-update_OAuth2.0"
	SourceOktaUpdateAuthorizationMethodTypeSourceOktaUpdateOAuth20WithPrivateKey SourceOktaUpdateAuthorizationMethodType = "source-okta-update_OAuth 2.0 with private key"
	SourceOktaUpdateAuthorizationMethodTypeSourceOktaUpdateAPIToken              SourceOktaUpdateAuthorizationMethodType = "source-okta-update_API Token"
)

type SourceOktaUpdateAuthorizationMethod struct {
	SourceOktaUpdateOAuth20               *SourceOktaUpdateOAuth20               `queryParam:"inline"`
	SourceOktaUpdateOAuth20WithPrivateKey *SourceOktaUpdateOAuth20WithPrivateKey `queryParam:"inline"`
	SourceOktaUpdateAPIToken              *SourceOktaUpdateAPIToken              `queryParam:"inline"`

	Type SourceOktaUpdateAuthorizationMethodType
}

func CreateSourceOktaUpdateAuthorizationMethodSourceOktaUpdateOAuth20(sourceOktaUpdateOAuth20 SourceOktaUpdateOAuth20) SourceOktaUpdateAuthorizationMethod {
	typ := SourceOktaUpdateAuthorizationMethodTypeSourceOktaUpdateOAuth20

	return SourceOktaUpdateAuthorizationMethod{
		SourceOktaUpdateOAuth20: &sourceOktaUpdateOAuth20,
		Type:                    typ,
	}
}

func CreateSourceOktaUpdateAuthorizationMethodSourceOktaUpdateOAuth20WithPrivateKey(sourceOktaUpdateOAuth20WithPrivateKey SourceOktaUpdateOAuth20WithPrivateKey) SourceOktaUpdateAuthorizationMethod {
	typ := SourceOktaUpdateAuthorizationMethodTypeSourceOktaUpdateOAuth20WithPrivateKey

	return SourceOktaUpdateAuthorizationMethod{
		SourceOktaUpdateOAuth20WithPrivateKey: &sourceOktaUpdateOAuth20WithPrivateKey,
		Type:                                  typ,
	}
}

func CreateSourceOktaUpdateAuthorizationMethodSourceOktaUpdateAPIToken(sourceOktaUpdateAPIToken SourceOktaUpdateAPIToken) SourceOktaUpdateAuthorizationMethod {
	typ := SourceOktaUpdateAuthorizationMethodTypeSourceOktaUpdateAPIToken

	return SourceOktaUpdateAuthorizationMethod{
		SourceOktaUpdateAPIToken: &sourceOktaUpdateAPIToken,
		Type:                     typ,
	}
}

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

	var sourceOktaUpdateAPIToken SourceOktaUpdateAPIToken = SourceOktaUpdateAPIToken{}
	if err := utils.UnmarshalJSON(data, &sourceOktaUpdateAPIToken, "", true, true); err == nil {
		u.SourceOktaUpdateAPIToken = &sourceOktaUpdateAPIToken
		u.Type = SourceOktaUpdateAuthorizationMethodTypeSourceOktaUpdateAPIToken
		return nil
	}

	var sourceOktaUpdateOAuth20 SourceOktaUpdateOAuth20 = SourceOktaUpdateOAuth20{}
	if err := utils.UnmarshalJSON(data, &sourceOktaUpdateOAuth20, "", true, true); err == nil {
		u.SourceOktaUpdateOAuth20 = &sourceOktaUpdateOAuth20
		u.Type = SourceOktaUpdateAuthorizationMethodTypeSourceOktaUpdateOAuth20
		return nil
	}

	var sourceOktaUpdateOAuth20WithPrivateKey SourceOktaUpdateOAuth20WithPrivateKey = SourceOktaUpdateOAuth20WithPrivateKey{}
	if err := utils.UnmarshalJSON(data, &sourceOktaUpdateOAuth20WithPrivateKey, "", true, true); err == nil {
		u.SourceOktaUpdateOAuth20WithPrivateKey = &sourceOktaUpdateOAuth20WithPrivateKey
		u.Type = SourceOktaUpdateAuthorizationMethodTypeSourceOktaUpdateOAuth20WithPrivateKey
		return nil
	}

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

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

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

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

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

type SourceOktaUpdate struct {
	Credentials *SourceOktaUpdateAuthorizationMethod `json:"credentials,omitempty"`
	// The Okta domain. See the <a href="https://docs.airbyte.com/integrations/sources/okta">docs</a> for instructions on how to find it.
	Domain *string `json:"domain,omitempty"`
	// UTC date and time in the format YYYY-MM-DDTHH:MM:SSZ. Any data before this date will not be replicated.
	StartDate *time.Time `json:"start_date,omitempty"`
}

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

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

func (o *SourceOktaUpdate) GetCredentials() *SourceOktaUpdateAuthorizationMethod {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceOktaUpdate) GetDomain() *string {
	if o == nil {
		return nil
	}
	return o.Domain
}

func (o *SourceOktaUpdate) GetStartDate() *time.Time {
	if o == nil {
		return nil
	}
	return o.StartDate
}
