// 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 *DestinationOracleResourceModel) ToSharedDestinationOracleCreateRequest() *shared.DestinationOracleCreateRequest {
	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 encryption *shared.DestinationOracleEncryption
	if r.Configuration.Encryption != nil {
		var destinationOracleUnencrypted *shared.DestinationOracleUnencrypted
		if r.Configuration.Encryption.Unencrypted != nil {
			destinationOracleUnencrypted = &shared.DestinationOracleUnencrypted{}
		}
		if destinationOracleUnencrypted != nil {
			encryption = &shared.DestinationOracleEncryption{
				DestinationOracleUnencrypted: destinationOracleUnencrypted,
			}
		}
		var destinationOracleNativeNetworkEncryptionNNE *shared.DestinationOracleNativeNetworkEncryptionNNE
		if r.Configuration.Encryption.NativeNetworkEncryptionNNE != nil {
			encryptionAlgorithm := new(shared.DestinationOracleEncryptionAlgorithm)
			if !r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.IsUnknown() && !r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.IsNull() {
				*encryptionAlgorithm = shared.DestinationOracleEncryptionAlgorithm(r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.ValueString())
			} else {
				encryptionAlgorithm = nil
			}
			destinationOracleNativeNetworkEncryptionNNE = &shared.DestinationOracleNativeNetworkEncryptionNNE{
				EncryptionAlgorithm: encryptionAlgorithm,
			}
		}
		if destinationOracleNativeNetworkEncryptionNNE != nil {
			encryption = &shared.DestinationOracleEncryption{
				DestinationOracleNativeNetworkEncryptionNNE: destinationOracleNativeNetworkEncryptionNNE,
			}
		}
		var destinationOracleTLSEncryptedVerifyCertificate *shared.DestinationOracleTLSEncryptedVerifyCertificate
		if r.Configuration.Encryption.TLSEncryptedVerifyCertificate != nil {
			var sslCertificate string
			sslCertificate = r.Configuration.Encryption.TLSEncryptedVerifyCertificate.SslCertificate.ValueString()

			destinationOracleTLSEncryptedVerifyCertificate = &shared.DestinationOracleTLSEncryptedVerifyCertificate{
				SslCertificate: sslCertificate,
			}
		}
		if destinationOracleTLSEncryptedVerifyCertificate != nil {
			encryption = &shared.DestinationOracleEncryption{
				DestinationOracleTLSEncryptedVerifyCertificate: destinationOracleTLSEncryptedVerifyCertificate,
			}
		}
	}
	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
	}
	rawDataSchema := new(string)
	if !r.Configuration.RawDataSchema.IsUnknown() && !r.Configuration.RawDataSchema.IsNull() {
		*rawDataSchema = r.Configuration.RawDataSchema.ValueString()
	} else {
		rawDataSchema = nil
	}
	schema := new(string)
	if !r.Configuration.Schema.IsUnknown() && !r.Configuration.Schema.IsNull() {
		*schema = r.Configuration.Schema.ValueString()
	} else {
		schema = nil
	}
	var sid string
	sid = r.Configuration.Sid.ValueString()

	var tunnelMethod *shared.DestinationOracleSSHTunnelMethod
	if r.Configuration.TunnelMethod != nil {
		var destinationOracleNoTunnel *shared.DestinationOracleNoTunnel
		if r.Configuration.TunnelMethod.NoTunnel != nil {
			destinationOracleNoTunnel = &shared.DestinationOracleNoTunnel{}
		}
		if destinationOracleNoTunnel != nil {
			tunnelMethod = &shared.DestinationOracleSSHTunnelMethod{
				DestinationOracleNoTunnel: destinationOracleNoTunnel,
			}
		}
		var destinationOracleSSHKeyAuthentication *shared.DestinationOracleSSHKeyAuthentication
		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()

			destinationOracleSSHKeyAuthentication = &shared.DestinationOracleSSHKeyAuthentication{
				SSHKey:     sshKey,
				TunnelHost: tunnelHost,
				TunnelPort: tunnelPort,
				TunnelUser: tunnelUser,
			}
		}
		if destinationOracleSSHKeyAuthentication != nil {
			tunnelMethod = &shared.DestinationOracleSSHTunnelMethod{
				DestinationOracleSSHKeyAuthentication: destinationOracleSSHKeyAuthentication,
			}
		}
		var destinationOraclePasswordAuthentication *shared.DestinationOraclePasswordAuthentication
		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()

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

	configuration := shared.DestinationOracle{
		Encryption:    encryption,
		Host:          host,
		JdbcURLParams: jdbcURLParams,
		Password:      password,
		Port:          port,
		RawDataSchema: rawDataSchema,
		Schema:        schema,
		Sid:           sid,
		TunnelMethod:  tunnelMethod,
		Username:      username,
	}
	out := shared.DestinationOracleCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}

func (r *DestinationOracleResourceModel) RefreshFromSharedDestinationResponse(resp *shared.DestinationResponse) {
	if resp != nil {
		r.CreatedAt = types.Int64Value(resp.CreatedAt)
		r.DefinitionID = types.StringValue(resp.DefinitionID)
		r.DestinationID = types.StringValue(resp.DestinationID)
		r.DestinationType = types.StringValue(resp.DestinationType)
		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.WorkspaceID = types.StringValue(resp.WorkspaceID)
	}
}

func (r *DestinationOracleResourceModel) ToSharedDestinationOraclePutRequest() *shared.DestinationOraclePutRequest {
	var name string
	name = r.Name.ValueString()

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

	var encryption *shared.DestinationOracleUpdateEncryption
	if r.Configuration.Encryption != nil {
		var destinationOracleUpdateUnencrypted *shared.DestinationOracleUpdateUnencrypted
		if r.Configuration.Encryption.Unencrypted != nil {
			destinationOracleUpdateUnencrypted = &shared.DestinationOracleUpdateUnencrypted{}
		}
		if destinationOracleUpdateUnencrypted != nil {
			encryption = &shared.DestinationOracleUpdateEncryption{
				DestinationOracleUpdateUnencrypted: destinationOracleUpdateUnencrypted,
			}
		}
		var destinationOracleUpdateNativeNetworkEncryptionNNE *shared.DestinationOracleUpdateNativeNetworkEncryptionNNE
		if r.Configuration.Encryption.NativeNetworkEncryptionNNE != nil {
			encryptionAlgorithm := new(shared.DestinationOracleUpdateEncryptionAlgorithm)
			if !r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.IsUnknown() && !r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.IsNull() {
				*encryptionAlgorithm = shared.DestinationOracleUpdateEncryptionAlgorithm(r.Configuration.Encryption.NativeNetworkEncryptionNNE.EncryptionAlgorithm.ValueString())
			} else {
				encryptionAlgorithm = nil
			}
			destinationOracleUpdateNativeNetworkEncryptionNNE = &shared.DestinationOracleUpdateNativeNetworkEncryptionNNE{
				EncryptionAlgorithm: encryptionAlgorithm,
			}
		}
		if destinationOracleUpdateNativeNetworkEncryptionNNE != nil {
			encryption = &shared.DestinationOracleUpdateEncryption{
				DestinationOracleUpdateNativeNetworkEncryptionNNE: destinationOracleUpdateNativeNetworkEncryptionNNE,
			}
		}
		var destinationOracleUpdateTLSEncryptedVerifyCertificate *shared.DestinationOracleUpdateTLSEncryptedVerifyCertificate
		if r.Configuration.Encryption.TLSEncryptedVerifyCertificate != nil {
			var sslCertificate string
			sslCertificate = r.Configuration.Encryption.TLSEncryptedVerifyCertificate.SslCertificate.ValueString()

			destinationOracleUpdateTLSEncryptedVerifyCertificate = &shared.DestinationOracleUpdateTLSEncryptedVerifyCertificate{
				SslCertificate: sslCertificate,
			}
		}
		if destinationOracleUpdateTLSEncryptedVerifyCertificate != nil {
			encryption = &shared.DestinationOracleUpdateEncryption{
				DestinationOracleUpdateTLSEncryptedVerifyCertificate: destinationOracleUpdateTLSEncryptedVerifyCertificate,
			}
		}
	}
	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
	}
	rawDataSchema := new(string)
	if !r.Configuration.RawDataSchema.IsUnknown() && !r.Configuration.RawDataSchema.IsNull() {
		*rawDataSchema = r.Configuration.RawDataSchema.ValueString()
	} else {
		rawDataSchema = nil
	}
	schema := new(string)
	if !r.Configuration.Schema.IsUnknown() && !r.Configuration.Schema.IsNull() {
		*schema = r.Configuration.Schema.ValueString()
	} else {
		schema = nil
	}
	var sid string
	sid = r.Configuration.Sid.ValueString()

	var tunnelMethod *shared.DestinationOracleUpdateSSHTunnelMethod
	if r.Configuration.TunnelMethod != nil {
		var destinationOracleUpdateNoTunnel *shared.DestinationOracleUpdateNoTunnel
		if r.Configuration.TunnelMethod.NoTunnel != nil {
			destinationOracleUpdateNoTunnel = &shared.DestinationOracleUpdateNoTunnel{}
		}
		if destinationOracleUpdateNoTunnel != nil {
			tunnelMethod = &shared.DestinationOracleUpdateSSHTunnelMethod{
				DestinationOracleUpdateNoTunnel: destinationOracleUpdateNoTunnel,
			}
		}
		var destinationOracleUpdateSSHKeyAuthentication *shared.DestinationOracleUpdateSSHKeyAuthentication
		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()

			destinationOracleUpdateSSHKeyAuthentication = &shared.DestinationOracleUpdateSSHKeyAuthentication{
				SSHKey:     sshKey,
				TunnelHost: tunnelHost,
				TunnelPort: tunnelPort,
				TunnelUser: tunnelUser,
			}
		}
		if destinationOracleUpdateSSHKeyAuthentication != nil {
			tunnelMethod = &shared.DestinationOracleUpdateSSHTunnelMethod{
				DestinationOracleUpdateSSHKeyAuthentication: destinationOracleUpdateSSHKeyAuthentication,
			}
		}
		var destinationOracleUpdatePasswordAuthentication *shared.DestinationOracleUpdatePasswordAuthentication
		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()

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

	configuration := shared.DestinationOracleUpdate{
		Encryption:    encryption,
		Host:          host,
		JdbcURLParams: jdbcURLParams,
		Password:      password,
		Port:          port,
		RawDataSchema: rawDataSchema,
		Schema:        schema,
		Sid:           sid,
		TunnelMethod:  tunnelMethod,
		Username:      username,
	}
	out := shared.DestinationOraclePutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
