// 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 *DestinationRedisResourceModel) ToSharedDestinationRedisCreateRequest() *shared.DestinationRedisCreateRequest {
	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()

	cacheType := new(shared.CacheType)
	if !r.Configuration.CacheType.IsUnknown() && !r.Configuration.CacheType.IsNull() {
		*cacheType = shared.CacheType(r.Configuration.CacheType.ValueString())
	} else {
		cacheType = nil
	}
	var host string
	host = r.Configuration.Host.ValueString()

	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
	}
	ssl := new(bool)
	if !r.Configuration.Ssl.IsUnknown() && !r.Configuration.Ssl.IsNull() {
		*ssl = r.Configuration.Ssl.ValueBool()
	} else {
		ssl = nil
	}
	var sslMode *shared.DestinationRedisSSLModes
	if r.Configuration.SslMode != nil {
		var destinationRedisDisable *shared.DestinationRedisDisable
		if r.Configuration.SslMode.Disable != nil {
			destinationRedisDisable = &shared.DestinationRedisDisable{}
		}
		if destinationRedisDisable != nil {
			sslMode = &shared.DestinationRedisSSLModes{
				DestinationRedisDisable: destinationRedisDisable,
			}
		}
		var destinationRedisVerifyFull *shared.DestinationRedisVerifyFull
		if r.Configuration.SslMode.VerifyFull != nil {
			var caCertificate string
			caCertificate = r.Configuration.SslMode.VerifyFull.CaCertificate.ValueString()

			var clientCertificate string
			clientCertificate = r.Configuration.SslMode.VerifyFull.ClientCertificate.ValueString()

			var clientKey string
			clientKey = r.Configuration.SslMode.VerifyFull.ClientKey.ValueString()

			clientKeyPassword := new(string)
			if !r.Configuration.SslMode.VerifyFull.ClientKeyPassword.IsUnknown() && !r.Configuration.SslMode.VerifyFull.ClientKeyPassword.IsNull() {
				*clientKeyPassword = r.Configuration.SslMode.VerifyFull.ClientKeyPassword.ValueString()
			} else {
				clientKeyPassword = nil
			}
			destinationRedisVerifyFull = &shared.DestinationRedisVerifyFull{
				CaCertificate:     caCertificate,
				ClientCertificate: clientCertificate,
				ClientKey:         clientKey,
				ClientKeyPassword: clientKeyPassword,
			}
		}
		if destinationRedisVerifyFull != nil {
			sslMode = &shared.DestinationRedisSSLModes{
				DestinationRedisVerifyFull: destinationRedisVerifyFull,
			}
		}
	}
	var tunnelMethod *shared.DestinationRedisSSHTunnelMethod
	if r.Configuration.TunnelMethod != nil {
		var destinationRedisNoTunnel *shared.DestinationRedisNoTunnel
		if r.Configuration.TunnelMethod.NoTunnel != nil {
			destinationRedisNoTunnel = &shared.DestinationRedisNoTunnel{}
		}
		if destinationRedisNoTunnel != nil {
			tunnelMethod = &shared.DestinationRedisSSHTunnelMethod{
				DestinationRedisNoTunnel: destinationRedisNoTunnel,
			}
		}
		var destinationRedisSSHKeyAuthentication *shared.DestinationRedisSSHKeyAuthentication
		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()

			destinationRedisSSHKeyAuthentication = &shared.DestinationRedisSSHKeyAuthentication{
				SSHKey:     sshKey,
				TunnelHost: tunnelHost,
				TunnelPort: tunnelPort,
				TunnelUser: tunnelUser,
			}
		}
		if destinationRedisSSHKeyAuthentication != nil {
			tunnelMethod = &shared.DestinationRedisSSHTunnelMethod{
				DestinationRedisSSHKeyAuthentication: destinationRedisSSHKeyAuthentication,
			}
		}
		var destinationRedisPasswordAuthentication *shared.DestinationRedisPasswordAuthentication
		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()

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

	configuration := shared.DestinationRedis{
		CacheType:    cacheType,
		Host:         host,
		Password:     password,
		Port:         port,
		Ssl:          ssl,
		SslMode:      sslMode,
		TunnelMethod: tunnelMethod,
		Username:     username,
	}
	out := shared.DestinationRedisCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}

func (r *DestinationRedisResourceModel) 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 *DestinationRedisResourceModel) ToSharedDestinationRedisPutRequest() *shared.DestinationRedisPutRequest {
	var name string
	name = r.Name.ValueString()

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

	cacheType := new(shared.DestinationRedisUpdateCacheType)
	if !r.Configuration.CacheType.IsUnknown() && !r.Configuration.CacheType.IsNull() {
		*cacheType = shared.DestinationRedisUpdateCacheType(r.Configuration.CacheType.ValueString())
	} else {
		cacheType = nil
	}
	var host string
	host = r.Configuration.Host.ValueString()

	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
	}
	ssl := new(bool)
	if !r.Configuration.Ssl.IsUnknown() && !r.Configuration.Ssl.IsNull() {
		*ssl = r.Configuration.Ssl.ValueBool()
	} else {
		ssl = nil
	}
	var sslMode *shared.DestinationRedisUpdateSSLModes
	if r.Configuration.SslMode != nil {
		var destinationRedisUpdateDisable *shared.DestinationRedisUpdateDisable
		if r.Configuration.SslMode.Disable != nil {
			destinationRedisUpdateDisable = &shared.DestinationRedisUpdateDisable{}
		}
		if destinationRedisUpdateDisable != nil {
			sslMode = &shared.DestinationRedisUpdateSSLModes{
				DestinationRedisUpdateDisable: destinationRedisUpdateDisable,
			}
		}
		var destinationRedisUpdateVerifyFull *shared.DestinationRedisUpdateVerifyFull
		if r.Configuration.SslMode.VerifyFull != nil {
			var caCertificate string
			caCertificate = r.Configuration.SslMode.VerifyFull.CaCertificate.ValueString()

			var clientCertificate string
			clientCertificate = r.Configuration.SslMode.VerifyFull.ClientCertificate.ValueString()

			var clientKey string
			clientKey = r.Configuration.SslMode.VerifyFull.ClientKey.ValueString()

			clientKeyPassword := new(string)
			if !r.Configuration.SslMode.VerifyFull.ClientKeyPassword.IsUnknown() && !r.Configuration.SslMode.VerifyFull.ClientKeyPassword.IsNull() {
				*clientKeyPassword = r.Configuration.SslMode.VerifyFull.ClientKeyPassword.ValueString()
			} else {
				clientKeyPassword = nil
			}
			destinationRedisUpdateVerifyFull = &shared.DestinationRedisUpdateVerifyFull{
				CaCertificate:     caCertificate,
				ClientCertificate: clientCertificate,
				ClientKey:         clientKey,
				ClientKeyPassword: clientKeyPassword,
			}
		}
		if destinationRedisUpdateVerifyFull != nil {
			sslMode = &shared.DestinationRedisUpdateSSLModes{
				DestinationRedisUpdateVerifyFull: destinationRedisUpdateVerifyFull,
			}
		}
	}
	var tunnelMethod *shared.DestinationRedisUpdateSSHTunnelMethod
	if r.Configuration.TunnelMethod != nil {
		var destinationRedisUpdateNoTunnel *shared.DestinationRedisUpdateNoTunnel
		if r.Configuration.TunnelMethod.NoTunnel != nil {
			destinationRedisUpdateNoTunnel = &shared.DestinationRedisUpdateNoTunnel{}
		}
		if destinationRedisUpdateNoTunnel != nil {
			tunnelMethod = &shared.DestinationRedisUpdateSSHTunnelMethod{
				DestinationRedisUpdateNoTunnel: destinationRedisUpdateNoTunnel,
			}
		}
		var destinationRedisUpdateSSHKeyAuthentication *shared.DestinationRedisUpdateSSHKeyAuthentication
		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()

			destinationRedisUpdateSSHKeyAuthentication = &shared.DestinationRedisUpdateSSHKeyAuthentication{
				SSHKey:     sshKey,
				TunnelHost: tunnelHost,
				TunnelPort: tunnelPort,
				TunnelUser: tunnelUser,
			}
		}
		if destinationRedisUpdateSSHKeyAuthentication != nil {
			tunnelMethod = &shared.DestinationRedisUpdateSSHTunnelMethod{
				DestinationRedisUpdateSSHKeyAuthentication: destinationRedisUpdateSSHKeyAuthentication,
			}
		}
		var destinationRedisUpdatePasswordAuthentication *shared.DestinationRedisUpdatePasswordAuthentication
		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()

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

	configuration := shared.DestinationRedisUpdate{
		CacheType:    cacheType,
		Host:         host,
		Password:     password,
		Port:         port,
		Ssl:          ssl,
		SslMode:      sslMode,
		TunnelMethod: tunnelMethod,
		Username:     username,
	}
	out := shared.DestinationRedisPutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
