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

// SourceSftpUpdateSchemasAuthMethod - Connect through ssh key
type SourceSftpUpdateSchemasAuthMethod string

const (
	SourceSftpUpdateSchemasAuthMethodSSHKeyAuth SourceSftpUpdateSchemasAuthMethod = "SSH_KEY_AUTH"
)

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

type SourceSftpUpdateSSHKeyAuthentication struct {
	// Connect through ssh key
	authMethod SourceSftpUpdateSchemasAuthMethod `const:"SSH_KEY_AUTH" json:"auth_method"`
	// OS-level user account ssh key credentials in RSA PEM format ( created with ssh-keygen -t rsa -m PEM -f myuser_rsa )
	AuthSSHKey string `json:"auth_ssh_key"`
}

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

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

func (o *SourceSftpUpdateSSHKeyAuthentication) GetAuthMethod() SourceSftpUpdateSchemasAuthMethod {
	return SourceSftpUpdateSchemasAuthMethodSSHKeyAuth
}

func (o *SourceSftpUpdateSSHKeyAuthentication) GetAuthSSHKey() string {
	if o == nil {
		return ""
	}
	return o.AuthSSHKey
}

// SourceSftpUpdateAuthMethod - Connect through password authentication
type SourceSftpUpdateAuthMethod string

const (
	SourceSftpUpdateAuthMethodSSHPasswordAuth SourceSftpUpdateAuthMethod = "SSH_PASSWORD_AUTH"
)

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

type SourceSftpUpdatePasswordAuthentication struct {
	// Connect through password authentication
	authMethod SourceSftpUpdateAuthMethod `const:"SSH_PASSWORD_AUTH" json:"auth_method"`
	// OS-level password for logging into the jump server host
	AuthUserPassword string `json:"auth_user_password"`
}

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

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

func (o *SourceSftpUpdatePasswordAuthentication) GetAuthMethod() SourceSftpUpdateAuthMethod {
	return SourceSftpUpdateAuthMethodSSHPasswordAuth
}

func (o *SourceSftpUpdatePasswordAuthentication) GetAuthUserPassword() string {
	if o == nil {
		return ""
	}
	return o.AuthUserPassword
}

type SourceSftpUpdateAuthenticationType string

const (
	SourceSftpUpdateAuthenticationTypeSourceSftpUpdatePasswordAuthentication SourceSftpUpdateAuthenticationType = "source-sftp-update_Password Authentication"
	SourceSftpUpdateAuthenticationTypeSourceSftpUpdateSSHKeyAuthentication   SourceSftpUpdateAuthenticationType = "source-sftp-update_SSH Key Authentication"
)

// SourceSftpUpdateAuthentication - The server authentication method
type SourceSftpUpdateAuthentication struct {
	SourceSftpUpdatePasswordAuthentication *SourceSftpUpdatePasswordAuthentication `queryParam:"inline"`
	SourceSftpUpdateSSHKeyAuthentication   *SourceSftpUpdateSSHKeyAuthentication   `queryParam:"inline"`

	Type SourceSftpUpdateAuthenticationType
}

func CreateSourceSftpUpdateAuthenticationSourceSftpUpdatePasswordAuthentication(sourceSftpUpdatePasswordAuthentication SourceSftpUpdatePasswordAuthentication) SourceSftpUpdateAuthentication {
	typ := SourceSftpUpdateAuthenticationTypeSourceSftpUpdatePasswordAuthentication

	return SourceSftpUpdateAuthentication{
		SourceSftpUpdatePasswordAuthentication: &sourceSftpUpdatePasswordAuthentication,
		Type:                                   typ,
	}
}

func CreateSourceSftpUpdateAuthenticationSourceSftpUpdateSSHKeyAuthentication(sourceSftpUpdateSSHKeyAuthentication SourceSftpUpdateSSHKeyAuthentication) SourceSftpUpdateAuthentication {
	typ := SourceSftpUpdateAuthenticationTypeSourceSftpUpdateSSHKeyAuthentication

	return SourceSftpUpdateAuthentication{
		SourceSftpUpdateSSHKeyAuthentication: &sourceSftpUpdateSSHKeyAuthentication,
		Type:                                 typ,
	}
}

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

	var sourceSftpUpdatePasswordAuthentication SourceSftpUpdatePasswordAuthentication = SourceSftpUpdatePasswordAuthentication{}
	if err := utils.UnmarshalJSON(data, &sourceSftpUpdatePasswordAuthentication, "", true, true); err == nil {
		u.SourceSftpUpdatePasswordAuthentication = &sourceSftpUpdatePasswordAuthentication
		u.Type = SourceSftpUpdateAuthenticationTypeSourceSftpUpdatePasswordAuthentication
		return nil
	}

	var sourceSftpUpdateSSHKeyAuthentication SourceSftpUpdateSSHKeyAuthentication = SourceSftpUpdateSSHKeyAuthentication{}
	if err := utils.UnmarshalJSON(data, &sourceSftpUpdateSSHKeyAuthentication, "", true, true); err == nil {
		u.SourceSftpUpdateSSHKeyAuthentication = &sourceSftpUpdateSSHKeyAuthentication
		u.Type = SourceSftpUpdateAuthenticationTypeSourceSftpUpdateSSHKeyAuthentication
		return nil
	}

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

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

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

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

type SourceSftpUpdate struct {
	// The server authentication method
	Credentials *SourceSftpUpdateAuthentication `json:"credentials,omitempty"`
	// The regular expression to specify files for sync in a chosen Folder Path
	FilePattern *string `default:"" json:"file_pattern"`
	// Coma separated file types. Currently only 'csv' and 'json' types are supported.
	FileTypes *string `default:"csv,json" json:"file_types"`
	// The directory to search files for sync
	FolderPath *string `default:"" json:"folder_path"`
	// The server host address
	Host string `json:"host"`
	// The server port
	Port *int64 `default:"22" json:"port"`
	// The server user
	User string `json:"user"`
}

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

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

func (o *SourceSftpUpdate) GetCredentials() *SourceSftpUpdateAuthentication {
	if o == nil {
		return nil
	}
	return o.Credentials
}

func (o *SourceSftpUpdate) GetFilePattern() *string {
	if o == nil {
		return nil
	}
	return o.FilePattern
}

func (o *SourceSftpUpdate) GetFileTypes() *string {
	if o == nil {
		return nil
	}
	return o.FileTypes
}

func (o *SourceSftpUpdate) GetFolderPath() *string {
	if o == nil {
		return nil
	}
	return o.FolderPath
}

func (o *SourceSftpUpdate) GetHost() string {
	if o == nil {
		return ""
	}
	return o.Host
}

func (o *SourceSftpUpdate) GetPort() *int64 {
	if o == nil {
		return nil
	}
	return o.Port
}

func (o *SourceSftpUpdate) GetUser() string {
	if o == nil {
		return ""
	}
	return o.User
}
