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

const (
	SourceElasticsearchUpdateSchemasAuthenticationMethodMethodBasic SourceElasticsearchUpdateSchemasAuthenticationMethodMethod = "basic"
)

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

// SourceElasticsearchUpdateUsernamePassword - Basic auth header with a username and password
type SourceElasticsearchUpdateUsernamePassword struct {
	method SourceElasticsearchUpdateSchemasAuthenticationMethodMethod `const:"basic" json:"method"`
	// Basic auth password to access a secure Elasticsearch server
	Password string `json:"password"`
	// Basic auth username to access a secure Elasticsearch server
	Username             string `json:"username"`
	AdditionalProperties any    `additionalProperties:"true" json:"-"`
}

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

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

func (o *SourceElasticsearchUpdateUsernamePassword) GetMethod() SourceElasticsearchUpdateSchemasAuthenticationMethodMethod {
	return SourceElasticsearchUpdateSchemasAuthenticationMethodMethodBasic
}

func (o *SourceElasticsearchUpdateUsernamePassword) GetPassword() string {
	if o == nil {
		return ""
	}
	return o.Password
}

func (o *SourceElasticsearchUpdateUsernamePassword) GetUsername() string {
	if o == nil {
		return ""
	}
	return o.Username
}

func (o *SourceElasticsearchUpdateUsernamePassword) GetAdditionalProperties() any {
	if o == nil {
		return nil
	}
	return o.AdditionalProperties
}

type SourceElasticsearchUpdateSchemasMethod string

const (
	SourceElasticsearchUpdateSchemasMethodSecret SourceElasticsearchUpdateSchemasMethod = "secret"
)

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

// SourceElasticsearchUpdateAPIKeySecret - Use a api key and secret combination to authenticate
type SourceElasticsearchUpdateAPIKeySecret struct {
	// The Key ID to used when accessing an enterprise Elasticsearch instance.
	APIKeyID string `json:"apiKeyId"`
	// The secret associated with the API Key ID.
	APIKeySecret         string                                 `json:"apiKeySecret"`
	method               SourceElasticsearchUpdateSchemasMethod `const:"secret" json:"method"`
	AdditionalProperties any                                    `additionalProperties:"true" json:"-"`
}

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

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

func (o *SourceElasticsearchUpdateAPIKeySecret) GetAPIKeyID() string {
	if o == nil {
		return ""
	}
	return o.APIKeyID
}

func (o *SourceElasticsearchUpdateAPIKeySecret) GetAPIKeySecret() string {
	if o == nil {
		return ""
	}
	return o.APIKeySecret
}

func (o *SourceElasticsearchUpdateAPIKeySecret) GetMethod() SourceElasticsearchUpdateSchemasMethod {
	return SourceElasticsearchUpdateSchemasMethodSecret
}

func (o *SourceElasticsearchUpdateAPIKeySecret) GetAdditionalProperties() any {
	if o == nil {
		return nil
	}
	return o.AdditionalProperties
}

type SourceElasticsearchUpdateMethod string

const (
	SourceElasticsearchUpdateMethodNone SourceElasticsearchUpdateMethod = "none"
)

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

// SourceElasticsearchUpdateNone - No authentication will be used
type SourceElasticsearchUpdateNone struct {
	method               SourceElasticsearchUpdateMethod `const:"none" json:"method"`
	AdditionalProperties any                             `additionalProperties:"true" json:"-"`
}

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

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

func (o *SourceElasticsearchUpdateNone) GetMethod() SourceElasticsearchUpdateMethod {
	return SourceElasticsearchUpdateMethodNone
}

func (o *SourceElasticsearchUpdateNone) GetAdditionalProperties() any {
	if o == nil {
		return nil
	}
	return o.AdditionalProperties
}

type SourceElasticsearchUpdateAuthenticationMethodType string

const (
	SourceElasticsearchUpdateAuthenticationMethodTypeSourceElasticsearchUpdateNone             SourceElasticsearchUpdateAuthenticationMethodType = "source-elasticsearch-update_None"
	SourceElasticsearchUpdateAuthenticationMethodTypeSourceElasticsearchUpdateAPIKeySecret     SourceElasticsearchUpdateAuthenticationMethodType = "source-elasticsearch-update_Api Key/Secret"
	SourceElasticsearchUpdateAuthenticationMethodTypeSourceElasticsearchUpdateUsernamePassword SourceElasticsearchUpdateAuthenticationMethodType = "source-elasticsearch-update_Username/Password"
)

// SourceElasticsearchUpdateAuthenticationMethod - The type of authentication to be used
type SourceElasticsearchUpdateAuthenticationMethod struct {
	SourceElasticsearchUpdateNone             *SourceElasticsearchUpdateNone             `queryParam:"inline"`
	SourceElasticsearchUpdateAPIKeySecret     *SourceElasticsearchUpdateAPIKeySecret     `queryParam:"inline"`
	SourceElasticsearchUpdateUsernamePassword *SourceElasticsearchUpdateUsernamePassword `queryParam:"inline"`

	Type SourceElasticsearchUpdateAuthenticationMethodType
}

func CreateSourceElasticsearchUpdateAuthenticationMethodSourceElasticsearchUpdateNone(sourceElasticsearchUpdateNone SourceElasticsearchUpdateNone) SourceElasticsearchUpdateAuthenticationMethod {
	typ := SourceElasticsearchUpdateAuthenticationMethodTypeSourceElasticsearchUpdateNone

	return SourceElasticsearchUpdateAuthenticationMethod{
		SourceElasticsearchUpdateNone: &sourceElasticsearchUpdateNone,
		Type:                          typ,
	}
}

func CreateSourceElasticsearchUpdateAuthenticationMethodSourceElasticsearchUpdateAPIKeySecret(sourceElasticsearchUpdateAPIKeySecret SourceElasticsearchUpdateAPIKeySecret) SourceElasticsearchUpdateAuthenticationMethod {
	typ := SourceElasticsearchUpdateAuthenticationMethodTypeSourceElasticsearchUpdateAPIKeySecret

	return SourceElasticsearchUpdateAuthenticationMethod{
		SourceElasticsearchUpdateAPIKeySecret: &sourceElasticsearchUpdateAPIKeySecret,
		Type:                                  typ,
	}
}

func CreateSourceElasticsearchUpdateAuthenticationMethodSourceElasticsearchUpdateUsernamePassword(sourceElasticsearchUpdateUsernamePassword SourceElasticsearchUpdateUsernamePassword) SourceElasticsearchUpdateAuthenticationMethod {
	typ := SourceElasticsearchUpdateAuthenticationMethodTypeSourceElasticsearchUpdateUsernamePassword

	return SourceElasticsearchUpdateAuthenticationMethod{
		SourceElasticsearchUpdateUsernamePassword: &sourceElasticsearchUpdateUsernamePassword,
		Type: typ,
	}
}

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

	var sourceElasticsearchUpdateNone SourceElasticsearchUpdateNone = SourceElasticsearchUpdateNone{}
	if err := utils.UnmarshalJSON(data, &sourceElasticsearchUpdateNone, "", true, true); err == nil {
		u.SourceElasticsearchUpdateNone = &sourceElasticsearchUpdateNone
		u.Type = SourceElasticsearchUpdateAuthenticationMethodTypeSourceElasticsearchUpdateNone
		return nil
	}

	var sourceElasticsearchUpdateAPIKeySecret SourceElasticsearchUpdateAPIKeySecret = SourceElasticsearchUpdateAPIKeySecret{}
	if err := utils.UnmarshalJSON(data, &sourceElasticsearchUpdateAPIKeySecret, "", true, true); err == nil {
		u.SourceElasticsearchUpdateAPIKeySecret = &sourceElasticsearchUpdateAPIKeySecret
		u.Type = SourceElasticsearchUpdateAuthenticationMethodTypeSourceElasticsearchUpdateAPIKeySecret
		return nil
	}

	var sourceElasticsearchUpdateUsernamePassword SourceElasticsearchUpdateUsernamePassword = SourceElasticsearchUpdateUsernamePassword{}
	if err := utils.UnmarshalJSON(data, &sourceElasticsearchUpdateUsernamePassword, "", true, true); err == nil {
		u.SourceElasticsearchUpdateUsernamePassword = &sourceElasticsearchUpdateUsernamePassword
		u.Type = SourceElasticsearchUpdateAuthenticationMethodTypeSourceElasticsearchUpdateUsernamePassword
		return nil
	}

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

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

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

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

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

type SourceElasticsearchUpdate struct {
	// The type of authentication to be used
	AuthenticationMethod *SourceElasticsearchUpdateAuthenticationMethod `json:"authenticationMethod,omitempty"`
	// The full url of the Elasticsearch server
	Endpoint string `json:"endpoint"`
}

func (o *SourceElasticsearchUpdate) GetAuthenticationMethod() *SourceElasticsearchUpdateAuthenticationMethod {
	if o == nil {
		return nil
	}
	return o.AuthenticationMethod
}

func (o *SourceElasticsearchUpdate) GetEndpoint() string {
	if o == nil {
		return ""
	}
	return o.Endpoint
}
