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

const (
	SourceLeverHiringSchemasAuthTypeAPIKey SourceLeverHiringSchemasAuthType = "Api Key"
)

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

type AuthenticateViaLeverAPIKey struct {
	// The Api Key of your Lever Hiring account.
	APIKey   string                            `json:"api_key"`
	authType *SourceLeverHiringSchemasAuthType `const:"Api Key" json:"auth_type,omitempty"`
}

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

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

func (o *AuthenticateViaLeverAPIKey) GetAPIKey() string {
	if o == nil {
		return ""
	}
	return o.APIKey
}

func (o *AuthenticateViaLeverAPIKey) GetAuthType() *SourceLeverHiringSchemasAuthType {
	return SourceLeverHiringSchemasAuthTypeAPIKey.ToPointer()
}

type SourceLeverHiringAuthType string

const (
	SourceLeverHiringAuthTypeClient SourceLeverHiringAuthType = "Client"
)

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

type AuthenticateViaLeverOAuth struct {
	authType *SourceLeverHiringAuthType `const:"Client" json:"auth_type,omitempty"`
	// The Client ID of your Lever Hiring developer application.
	ClientID *string `json:"client_id,omitempty"`
	// The Client Secret of your Lever Hiring developer application.
	ClientSecret *string `json:"client_secret,omitempty"`
	// The token for obtaining new access token.
	RefreshToken string `json:"refresh_token"`
}

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

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

func (o *AuthenticateViaLeverOAuth) GetAuthType() *SourceLeverHiringAuthType {
	return SourceLeverHiringAuthTypeClient.ToPointer()
}

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

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

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

type SourceLeverHiringAuthenticationMechanismType string

const (
	SourceLeverHiringAuthenticationMechanismTypeAuthenticateViaLeverOAuth  SourceLeverHiringAuthenticationMechanismType = "Authenticate via Lever (OAuth)"
	SourceLeverHiringAuthenticationMechanismTypeAuthenticateViaLeverAPIKey SourceLeverHiringAuthenticationMechanismType = "Authenticate via Lever (Api Key)"
)

// SourceLeverHiringAuthenticationMechanism - Choose how to authenticate to Lever Hiring.
type SourceLeverHiringAuthenticationMechanism struct {
	AuthenticateViaLeverOAuth  *AuthenticateViaLeverOAuth  `queryParam:"inline"`
	AuthenticateViaLeverAPIKey *AuthenticateViaLeverAPIKey `queryParam:"inline"`

	Type SourceLeverHiringAuthenticationMechanismType
}

func CreateSourceLeverHiringAuthenticationMechanismAuthenticateViaLeverOAuth(authenticateViaLeverOAuth AuthenticateViaLeverOAuth) SourceLeverHiringAuthenticationMechanism {
	typ := SourceLeverHiringAuthenticationMechanismTypeAuthenticateViaLeverOAuth

	return SourceLeverHiringAuthenticationMechanism{
		AuthenticateViaLeverOAuth: &authenticateViaLeverOAuth,
		Type:                      typ,
	}
}

func CreateSourceLeverHiringAuthenticationMechanismAuthenticateViaLeverAPIKey(authenticateViaLeverAPIKey AuthenticateViaLeverAPIKey) SourceLeverHiringAuthenticationMechanism {
	typ := SourceLeverHiringAuthenticationMechanismTypeAuthenticateViaLeverAPIKey

	return SourceLeverHiringAuthenticationMechanism{
		AuthenticateViaLeverAPIKey: &authenticateViaLeverAPIKey,
		Type:                       typ,
	}
}

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

	var authenticateViaLeverAPIKey AuthenticateViaLeverAPIKey = AuthenticateViaLeverAPIKey{}
	if err := utils.UnmarshalJSON(data, &authenticateViaLeverAPIKey, "", true, true); err == nil {
		u.AuthenticateViaLeverAPIKey = &authenticateViaLeverAPIKey
		u.Type = SourceLeverHiringAuthenticationMechanismTypeAuthenticateViaLeverAPIKey
		return nil
	}

	var authenticateViaLeverOAuth AuthenticateViaLeverOAuth = AuthenticateViaLeverOAuth{}
	if err := utils.UnmarshalJSON(data, &authenticateViaLeverOAuth, "", true, true); err == nil {
		u.AuthenticateViaLeverOAuth = &authenticateViaLeverOAuth
		u.Type = SourceLeverHiringAuthenticationMechanismTypeAuthenticateViaLeverOAuth
		return nil
	}

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

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

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

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

// SourceLeverHiringEnvironment - The environment in which you'd like to replicate data for Lever. This is used to determine which Lever API endpoint to use.
type SourceLeverHiringEnvironment string

const (
	SourceLeverHiringEnvironmentProduction SourceLeverHiringEnvironment = "Production"
	SourceLeverHiringEnvironmentSandbox    SourceLeverHiringEnvironment = "Sandbox"
)

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

type LeverHiring string

const (
	LeverHiringLeverHiring LeverHiring = "lever-hiring"
)

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

type SourceLeverHiring struct {
	// Choose how to authenticate to Lever Hiring.
	Credentials *SourceLeverHiringAuthenticationMechanism `json:"credentials,omitempty"`
	// The environment in which you'd like to replicate data for Lever. This is used to determine which Lever API endpoint to use.
	Environment *SourceLeverHiringEnvironment `default:"Sandbox" json:"environment"`
	// UTC date and time in the format 2017-01-25T00:00:00Z. Any data before this date will not be replicated. Note that it will be used only in the following incremental streams: comments, commits, and issues.
	StartDate  string      `json:"start_date"`
	sourceType LeverHiring `const:"lever-hiring" json:"sourceType"`
}

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

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

func (o *SourceLeverHiring) GetCredentials() *SourceLeverHiringAuthenticationMechanism {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceLeverHiring) GetEnvironment() *SourceLeverHiringEnvironment {
	if o == nil {
		return nil
	}
	return o.Environment
}

func (o *SourceLeverHiring) GetStartDate() string {
	if o == nil {
		return ""
	}
	return o.StartDate
}

func (o *SourceLeverHiring) GetSourceType() LeverHiring {
	return LeverHiringLeverHiring
}
