// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.

package provider

import (
	tfTypes "github.com/airbytehq/terraform-provider-airbyte/internal/provider/types"
	"github.com/airbytehq/terraform-provider-airbyte/internal/sdk/models/shared"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func (r *SourceOracleResourceModel) ToSharedSourceOracleCreateRequest() *shared.SourceOracleCreateRequest {
	var name string
	name = r.Name.ValueString()

	definitionID := new(string)
	if !r.DefinitionID.IsUnknown() && !r.DefinitionID.IsNull() {
		*definitionID = r.DefinitionID.ValueString()
	} else {
		definitionID = nil
	}
	var workspaceID string
	workspaceID = r.WorkspaceID.ValueString()

	var connectionData *shared.ConnectBy
	if r.Configuration.ConnectionData != nil {
		var serviceName *shared.ServiceName
		if r.Configuration.ConnectionData.ServiceName != nil {
			var serviceName1 string
			serviceName1 = r.Configuration.ConnectionData.ServiceName.ServiceName.ValueString()

			serviceName = &shared.ServiceName{
				ServiceName: serviceName1,
			}
		}
		if serviceName != nil {
			connectionData = &shared.ConnectBy{
				ServiceName: serviceName,
			}
		}
		var systemIDSID *shared.SystemIDSID
		if r.Configuration.ConnectionData.SystemIDSID != nil {
			var sid string
			sid = r.Configuration.ConnectionData.SystemIDSID.Sid.ValueString()

			systemIDSID = &shared.SystemIDSID{
				Sid: sid,
			}
		}
		if systemIDSID != nil {
			connectionData = &shared.ConnectBy{
				SystemIDSID: systemIDSID,
			}
		}
	}
	var encryption *shared.SourceOracleEncryption
	if r.Configuration.Encryption != nil {
		var sourceOracleUnencrypted *shared.SourceOracleUnencrypted
		if r.Configuration.Encryption.Unencrypted != nil {
			sourceOracleUnencrypted = &shared.SourceOracleUnencrypted{}
		}
		if sourceOracleUnencrypted != nil {
			encryption = &shared.SourceOracleEncryption{
				SourceOracleUnencrypted: sourceOracleUnencrypted,
			}
		}
		var nativeNetworkEncryptionNNE *shared.NativeNetworkEncryptionNNE
		if r.Configuration.Encryption.NativeNetworkEncryptionNNE != nil {
			encryptionAlgorithm := new(shared.EncryptionAlgorithm)
			if !r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.IsUnknown() && !r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.IsNull() {
				*encryptionAlgorithm = shared.EncryptionAlgorithm(r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.ValueString())
			} else {
				encryptionAlgorithm = nil
			}
			nativeNetworkEncryptionNNE = &shared.NativeNetworkEncryptionNNE{
				EncryptionAlgorithm: encryptionAlgorithm,
			}
		}
		if nativeNetworkEncryptionNNE != nil {
			encryption = &shared.SourceOracleEncryption{
				NativeNetworkEncryptionNNE: nativeNetworkEncryptionNNE,
			}
		}
		var tlsEncryptedVerifyCertificate *shared.TLSEncryptedVerifyCertificate
		if r.Configuration.Encryption.TLSEncryptedVerifyCertificate != nil {
			var sslCertificate string
			sslCertificate = r.Configuration.Encryption.TLSEncryptedVerifyCertificate.SslCertificate.ValueString()

			tlsEncryptedVerifyCertificate = &shared.TLSEncryptedVerifyCertificate{
				SslCertificate: sslCertificate,
			}
		}
		if tlsEncryptedVerifyCertificate != nil {
			encryption = &shared.SourceOracleEncryption{
				TLSEncryptedVerifyCertificate: tlsEncryptedVerifyCertificate,
			}
		}
	}
	var host string
	host = r.Configuration.Host.ValueString()

	jdbcURLParams := new(string)
	if !r.Configuration.JdbcURLParams.IsUnknown() && !r.Configuration.JdbcURLParams.IsNull() {
		*jdbcURLParams = r.Configuration.JdbcURLParams.ValueString()
	} else {
		jdbcURLParams = nil
	}
	password := new(string)
	if !r.Configuration.Password.IsUnknown() && !r.Configuration.Password.IsNull() {
		*password = r.Configuration.Password.ValueString()
	} else {
		password = nil
	}
	port := new(int64)
	if !r.Configuration.Port.IsUnknown() && !r.Configuration.Port.IsNull() {
		*port = r.Configuration.Port.ValueInt64()
	} else {
		port = nil
	}
	var schemas []string = []string{}
	for _, schemasItem := range r.Configuration.Schemas {
		schemas = append(schemas, schemasItem.ValueString())
	}
	var tunnelMethod *shared.SourceOracleSSHTunnelMethod
	if r.Configuration.TunnelMethod != nil {
		var sourceOracleNoTunnel *shared.SourceOracleNoTunnel
		if r.Configuration.TunnelMethod.NoTunnel != nil {
			sourceOracleNoTunnel = &shared.SourceOracleNoTunnel{}
		}
		if sourceOracleNoTunnel != nil {
			tunnelMethod = &shared.SourceOracleSSHTunnelMethod{
				SourceOracleNoTunnel: sourceOracleNoTunnel,
			}
		}
		var sourceOracleSSHKeyAuthentication *shared.SourceOracleSSHKeyAuthentication
		if r.Configuration.TunnelMethod.SSHKeyAuthentication != nil {
			var sshKey string
			sshKey = r.Configuration.TunnelMethod.SSHKeyAuthentication.SSHKey.ValueString()

			var tunnelHost string
			tunnelHost = r.Configuration.TunnelMethod.SSHKeyAuthentication.TunnelHost.ValueString()

			tunnelPort := new(int64)
			if !r.Configuration.TunnelMethod.SSHKeyAuthentication.TunnelPort.IsUnknown() && !r.Configuration.TunnelMethod.SSHKeyAuthentication.TunnelPort.IsNull() {
				*tunnelPort = r.Configuration.TunnelMethod.SSHKeyAuthentication.TunnelPort.ValueInt64()
			} else {
				tunnelPort = nil
			}
			var tunnelUser string
			tunnelUser = r.Configuration.TunnelMethod.SSHKeyAuthentication.TunnelUser.ValueString()

			sourceOracleSSHKeyAuthentication = &shared.SourceOracleSSHKeyAuthentication{
				SSHKey:     sshKey,
				TunnelHost: tunnelHost,
				TunnelPort: tunnelPort,
				TunnelUser: tunnelUser,
			}
		}
		if sourceOracleSSHKeyAuthentication != nil {
			tunnelMethod = &shared.SourceOracleSSHTunnelMethod{
				SourceOracleSSHKeyAuthentication: sourceOracleSSHKeyAuthentication,
			}
		}
		var sourceOraclePasswordAuthentication *shared.SourceOraclePasswordAuthentication
		if r.Configuration.TunnelMethod.PasswordAuthentication != nil {
			var tunnelHost1 string
			tunnelHost1 = r.Configuration.TunnelMethod.PasswordAuthentication.TunnelHost.ValueString()

			tunnelPort1 := new(int64)
			if !r.Configuration.TunnelMethod.PasswordAuthentication.TunnelPort.IsUnknown() && !r.Configuration.TunnelMethod.PasswordAuthentication.TunnelPort.IsNull() {
				*tunnelPort1 = r.Configuration.TunnelMethod.PasswordAuthentication.TunnelPort.ValueInt64()
			} else {
				tunnelPort1 = nil
			}
			var tunnelUser1 string
			tunnelUser1 = r.Configuration.TunnelMethod.PasswordAuthentication.TunnelUser.ValueString()

			var tunnelUserPassword string
			tunnelUserPassword = r.Configuration.TunnelMethod.PasswordAuthentication.TunnelUserPassword.ValueString()

			sourceOraclePasswordAuthentication = &shared.SourceOraclePasswordAuthentication{
				TunnelHost:         tunnelHost1,
				TunnelPort:         tunnelPort1,
				TunnelUser:         tunnelUser1,
				TunnelUserPassword: tunnelUserPassword,
			}
		}
		if sourceOraclePasswordAuthentication != nil {
			tunnelMethod = &shared.SourceOracleSSHTunnelMethod{
				SourceOraclePasswordAuthentication: sourceOraclePasswordAuthentication,
			}
		}
	}
	var username string
	username = r.Configuration.Username.ValueString()

	configuration := shared.SourceOracle{
		ConnectionData: connectionData,
		Encryption:     encryption,
		Host:           host,
		JdbcURLParams:  jdbcURLParams,
		Password:       password,
		Port:           port,
		Schemas:        schemas,
		TunnelMethod:   tunnelMethod,
		Username:       username,
	}
	secretID := new(string)
	if !r.SecretID.IsUnknown() && !r.SecretID.IsNull() {
		*secretID = r.SecretID.ValueString()
	} else {
		secretID = nil
	}
	out := shared.SourceOracleCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
		SecretID:      secretID,
	}
	return &out
}

func (r *SourceOracleResourceModel) RefreshFromSharedSourceResponse(resp *shared.SourceResponse) {
	if resp != nil {
		r.CreatedAt = types.Int64Value(resp.CreatedAt)
		r.DefinitionID = types.StringValue(resp.DefinitionID)
		r.Name = types.StringValue(resp.Name)
		if resp.ResourceAllocation == nil {
			r.ResourceAllocation = nil
		} else {
			r.ResourceAllocation = &tfTypes.ScopedResourceRequirements{}
			if resp.ResourceAllocation.Default == nil {
				r.ResourceAllocation.Default = nil
			} else {
				r.ResourceAllocation.Default = &tfTypes.ResourceRequirements{}
				r.ResourceAllocation.Default.CPULimit = types.StringPointerValue(resp.ResourceAllocation.Default.CPULimit)
				r.ResourceAllocation.Default.CPURequest = types.StringPointerValue(resp.ResourceAllocation.Default.CPURequest)
				r.ResourceAllocation.Default.EphemeralStorageLimit = types.StringPointerValue(resp.ResourceAllocation.Default.EphemeralStorageLimit)
				r.ResourceAllocation.Default.EphemeralStorageRequest = types.StringPointerValue(resp.ResourceAllocation.Default.EphemeralStorageRequest)
				r.ResourceAllocation.Default.MemoryLimit = types.StringPointerValue(resp.ResourceAllocation.Default.MemoryLimit)
				r.ResourceAllocation.Default.MemoryRequest = types.StringPointerValue(resp.ResourceAllocation.Default.MemoryRequest)
			}
			r.ResourceAllocation.JobSpecific = []tfTypes.JobTypeResourceLimit{}
			if len(r.ResourceAllocation.JobSpecific) > len(resp.ResourceAllocation.JobSpecific) {
				r.ResourceAllocation.JobSpecific = r.ResourceAllocation.JobSpecific[:len(resp.ResourceAllocation.JobSpecific)]
			}
			for jobSpecificCount, jobSpecificItem := range resp.ResourceAllocation.JobSpecific {
				var jobSpecific1 tfTypes.JobTypeResourceLimit
				jobSpecific1.JobType = types.StringValue(string(jobSpecificItem.JobType))
				jobSpecific1.ResourceRequirements.CPULimit = types.StringPointerValue(jobSpecificItem.ResourceRequirements.CPULimit)
				jobSpecific1.ResourceRequirements.CPURequest = types.StringPointerValue(jobSpecificItem.ResourceRequirements.CPURequest)
				jobSpecific1.ResourceRequirements.EphemeralStorageLimit = types.StringPointerValue(jobSpecificItem.ResourceRequirements.EphemeralStorageLimit)
				jobSpecific1.ResourceRequirements.EphemeralStorageRequest = types.StringPointerValue(jobSpecificItem.ResourceRequirements.EphemeralStorageRequest)
				jobSpecific1.ResourceRequirements.MemoryLimit = types.StringPointerValue(jobSpecificItem.ResourceRequirements.MemoryLimit)
				jobSpecific1.ResourceRequirements.MemoryRequest = types.StringPointerValue(jobSpecificItem.ResourceRequirements.MemoryRequest)
				if jobSpecificCount+1 > len(r.ResourceAllocation.JobSpecific) {
					r.ResourceAllocation.JobSpecific = append(r.ResourceAllocation.JobSpecific, jobSpecific1)
				} else {
					r.ResourceAllocation.JobSpecific[jobSpecificCount].JobType = jobSpecific1.JobType
					r.ResourceAllocation.JobSpecific[jobSpecificCount].ResourceRequirements = jobSpecific1.ResourceRequirements
				}
			}
		}
		r.SourceID = types.StringValue(resp.SourceID)
		r.SourceType = types.StringValue(resp.SourceType)
		r.WorkspaceID = types.StringValue(resp.WorkspaceID)
	}
}

func (r *SourceOracleResourceModel) ToSharedSourceOraclePutRequest() *shared.SourceOraclePutRequest {
	var name string
	name = r.Name.ValueString()

	var workspaceID string
	workspaceID = r.WorkspaceID.ValueString()

	var connectionData *shared.SourceOracleUpdateConnectBy
	if r.Configuration.ConnectionData != nil {
		var sourceOracleUpdateServiceName *shared.SourceOracleUpdateServiceName
		if r.Configuration.ConnectionData.ServiceName != nil {
			var serviceName string
			serviceName = r.Configuration.ConnectionData.ServiceName.ServiceName.ValueString()

			sourceOracleUpdateServiceName = &shared.SourceOracleUpdateServiceName{
				ServiceName: serviceName,
			}
		}
		if sourceOracleUpdateServiceName != nil {
			connectionData = &shared.SourceOracleUpdateConnectBy{
				SourceOracleUpdateServiceName: sourceOracleUpdateServiceName,
			}
		}
		var sourceOracleUpdateSystemIDSID *shared.SourceOracleUpdateSystemIDSID
		if r.Configuration.ConnectionData.SystemIDSID != nil {
			var sid string
			sid = r.Configuration.ConnectionData.SystemIDSID.Sid.ValueString()

			sourceOracleUpdateSystemIDSID = &shared.SourceOracleUpdateSystemIDSID{
				Sid: sid,
			}
		}
		if sourceOracleUpdateSystemIDSID != nil {
			connectionData = &shared.SourceOracleUpdateConnectBy{
				SourceOracleUpdateSystemIDSID: sourceOracleUpdateSystemIDSID,
			}
		}
	}
	var encryption *shared.SourceOracleUpdateEncryption
	if r.Configuration.Encryption != nil {
		var sourceOracleUpdateUnencrypted *shared.SourceOracleUpdateUnencrypted
		if r.Configuration.Encryption.Unencrypted != nil {
			sourceOracleUpdateUnencrypted = &shared.SourceOracleUpdateUnencrypted{}
		}
		if sourceOracleUpdateUnencrypted != nil {
			encryption = &shared.SourceOracleUpdateEncryption{
				SourceOracleUpdateUnencrypted: sourceOracleUpdateUnencrypted,
			}
		}
		var sourceOracleUpdateNativeNetworkEncryptionNNE *shared.SourceOracleUpdateNativeNetworkEncryptionNNE
		if r.Configuration.Encryption.NativeNetworkEncryptionNNE != nil {
			encryptionAlgorithm := new(shared.SourceOracleUpdateEncryptionAlgorithm)
			if !r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.IsUnknown() && !r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.IsNull() {
				*encryptionAlgorithm = shared.SourceOracleUpdateEncryptionAlgorithm(r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.ValueString())
			} else {
				encryptionAlgorithm = nil
			}
			sourceOracleUpdateNativeNetworkEncryptionNNE = &shared.SourceOracleUpdateNativeNetworkEncryptionNNE{
				EncryptionAlgorithm: encryptionAlgorithm,
			}
		}
		if sourceOracleUpdateNativeNetworkEncryptionNNE != nil {
			encryption = &shared.SourceOracleUpdateEncryption{
				SourceOracleUpdateNativeNetworkEncryptionNNE: sourceOracleUpdateNativeNetworkEncryptionNNE,
			}
		}
		var sourceOracleUpdateTLSEncryptedVerifyCertificate *shared.SourceOracleUpdateTLSEncryptedVerifyCertificate
		if r.Configuration.Encryption.TLSEncryptedVerifyCertificate != nil {
			var sslCertificate string
			sslCertificate = r.Configuration.Encryption.TLSEncryptedVerifyCertificate.SslCertificate.ValueString()

			sourceOracleUpdateTLSEncryptedVerifyCertificate = &shared.SourceOracleUpdateTLSEncryptedVerifyCertificate{
				SslCertificate: sslCertificate,
			}
		}
		if sourceOracleUpdateTLSEncryptedVerifyCertificate != nil {
			encryption = &shared.SourceOracleUpdateEncryption{
				SourceOracleUpdateTLSEncryptedVerifyCertificate: sourceOracleUpdateTLSEncryptedVerifyCertificate,
			}
		}
	}
	var host string
	host = r.Configuration.Host.ValueString()

	jdbcURLParams := new(string)
	if !r.Configuration.JdbcURLParams.IsUnknown() && !r.Configuration.JdbcURLParams.IsNull() {
		*jdbcURLParams = r.Configuration.JdbcURLParams.ValueString()
	} else {
		jdbcURLParams = nil
	}
	password := new(string)
	if !r.Configuration.Password.IsUnknown() && !r.Configuration.Password.IsNull() {
		*password = r.Configuration.Password.ValueString()
	} else {
		password = nil
	}
	port := new(int64)
	if !r.Configuration.Port.IsUnknown() && !r.Configuration.Port.IsNull() {
		*port = r.Configuration.Port.ValueInt64()
	} else {
		port = nil
	}
	var schemas []string = []string{}
	for _, schemasItem := range r.Configuration.Schemas {
		schemas = append(schemas, schemasItem.ValueString())
	}
	var tunnelMethod *shared.SourceOracleUpdateSSHTunnelMethod
	if r.Configuration.TunnelMethod != nil {
		var sourceOracleUpdateNoTunnel *shared.SourceOracleUpdateNoTunnel
		if r.Configuration.TunnelMethod.NoTunnel != nil {
			sourceOracleUpdateNoTunnel = &shared.SourceOracleUpdateNoTunnel{}
		}
		if sourceOracleUpdateNoTunnel != nil {
			tunnelMethod = &shared.SourceOracleUpdateSSHTunnelMethod{
				SourceOracleUpdateNoTunnel: sourceOracleUpdateNoTunnel,
			}
		}
		var sourceOracleUpdateSSHKeyAuthentication *shared.SourceOracleUpdateSSHKeyAuthentication
		if r.Configuration.TunnelMethod.SSHKeyAuthentication != nil {
			var sshKey string
			sshKey = r.Configuration.TunnelMethod.SSHKeyAuthentication.SSHKey.ValueString()

			var tunnelHost string
			tunnelHost = r.Configuration.TunnelMethod.SSHKeyAuthentication.TunnelHost.ValueString()

			tunnelPort := new(int64)
			if !r.Configuration.TunnelMethod.SSHKeyAuthentication.TunnelPort.IsUnknown() && !r.Configuration.TunnelMethod.SSHKeyAuthentication.TunnelPort.IsNull() {
				*tunnelPort = r.Configuration.TunnelMethod.SSHKeyAuthentication.TunnelPort.ValueInt64()
			} else {
				tunnelPort = nil
			}
			var tunnelUser string
			tunnelUser = r.Configuration.TunnelMethod.SSHKeyAuthentication.TunnelUser.ValueString()

			sourceOracleUpdateSSHKeyAuthentication = &shared.SourceOracleUpdateSSHKeyAuthentication{
				SSHKey:     sshKey,
				TunnelHost: tunnelHost,
				TunnelPort: tunnelPort,
				TunnelUser: tunnelUser,
			}
		}
		if sourceOracleUpdateSSHKeyAuthentication != nil {
			tunnelMethod = &shared.SourceOracleUpdateSSHTunnelMethod{
				SourceOracleUpdateSSHKeyAuthentication: sourceOracleUpdateSSHKeyAuthentication,
			}
		}
		var sourceOracleUpdatePasswordAuthentication *shared.SourceOracleUpdatePasswordAuthentication
		if r.Configuration.TunnelMethod.PasswordAuthentication != nil {
			var tunnelHost1 string
			tunnelHost1 = r.Configuration.TunnelMethod.PasswordAuthentication.TunnelHost.ValueString()

			tunnelPort1 := new(int64)
			if !r.Configuration.TunnelMethod.PasswordAuthentication.TunnelPort.IsUnknown() && !r.Configuration.TunnelMethod.PasswordAuthentication.TunnelPort.IsNull() {
				*tunnelPort1 = r.Configuration.TunnelMethod.PasswordAuthentication.TunnelPort.ValueInt64()
			} else {
				tunnelPort1 = nil
			}
			var tunnelUser1 string
			tunnelUser1 = r.Configuration.TunnelMethod.PasswordAuthentication.TunnelUser.ValueString()

			var tunnelUserPassword string
			tunnelUserPassword = r.Configuration.TunnelMethod.PasswordAuthentication.TunnelUserPassword.ValueString()

			sourceOracleUpdatePasswordAuthentication = &shared.SourceOracleUpdatePasswordAuthentication{
				TunnelHost:         tunnelHost1,
				TunnelPort:         tunnelPort1,
				TunnelUser:         tunnelUser1,
				TunnelUserPassword: tunnelUserPassword,
			}
		}
		if sourceOracleUpdatePasswordAuthentication != nil {
			tunnelMethod = &shared.SourceOracleUpdateSSHTunnelMethod{
				SourceOracleUpdatePasswordAuthentication: sourceOracleUpdatePasswordAuthentication,
			}
		}
	}
	var username string
	username = r.Configuration.Username.ValueString()

	configuration := shared.SourceOracleUpdate{
		ConnectionData: connectionData,
		Encryption:     encryption,
		Host:           host,
		JdbcURLParams:  jdbcURLParams,
		Password:       password,
		Port:           port,
		Schemas:        schemas,
		TunnelMethod:   tunnelMethod,
		Username:       username,
	}
	out := shared.SourceOraclePutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
