// 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 *DestinationRedshiftResourceModel) ToSharedDestinationRedshiftCreateRequest() *shared.DestinationRedshiftCreateRequest {
	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 database string
	database = r.Configuration.Database.ValueString()

	disableTypeDedupe := new(bool)
	if !r.Configuration.DisableTypeDedupe.IsUnknown() && !r.Configuration.DisableTypeDedupe.IsNull() {
		*disableTypeDedupe = r.Configuration.DisableTypeDedupe.ValueBool()
	} else {
		disableTypeDedupe = nil
	}
	dropCascade := new(bool)
	if !r.Configuration.DropCascade.IsUnknown() && !r.Configuration.DropCascade.IsNull() {
		*dropCascade = r.Configuration.DropCascade.ValueBool()
	} else {
		dropCascade = nil
	}
	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
	}
	var password string
	password = r.Configuration.Password.ValueString()

	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 tunnelMethod *shared.DestinationRedshiftSSHTunnelMethod
	if r.Configuration.TunnelMethod != nil {
		var destinationRedshiftNoTunnel *shared.DestinationRedshiftNoTunnel
		if r.Configuration.TunnelMethod.NoTunnel != nil {
			destinationRedshiftNoTunnel = &shared.DestinationRedshiftNoTunnel{}
		}
		if destinationRedshiftNoTunnel != nil {
			tunnelMethod = &shared.DestinationRedshiftSSHTunnelMethod{
				DestinationRedshiftNoTunnel: destinationRedshiftNoTunnel,
			}
		}
		var destinationRedshiftSSHKeyAuthentication *shared.DestinationRedshiftSSHKeyAuthentication
		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()

			destinationRedshiftSSHKeyAuthentication = &shared.DestinationRedshiftSSHKeyAuthentication{
				SSHKey:     sshKey,
				TunnelHost: tunnelHost,
				TunnelPort: tunnelPort,
				TunnelUser: tunnelUser,
			}
		}
		if destinationRedshiftSSHKeyAuthentication != nil {
			tunnelMethod = &shared.DestinationRedshiftSSHTunnelMethod{
				DestinationRedshiftSSHKeyAuthentication: destinationRedshiftSSHKeyAuthentication,
			}
		}
		var destinationRedshiftPasswordAuthentication *shared.DestinationRedshiftPasswordAuthentication
		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()

			destinationRedshiftPasswordAuthentication = &shared.DestinationRedshiftPasswordAuthentication{
				TunnelHost:         tunnelHost1,
				TunnelPort:         tunnelPort1,
				TunnelUser:         tunnelUser1,
				TunnelUserPassword: tunnelUserPassword,
			}
		}
		if destinationRedshiftPasswordAuthentication != nil {
			tunnelMethod = &shared.DestinationRedshiftSSHTunnelMethod{
				DestinationRedshiftPasswordAuthentication: destinationRedshiftPasswordAuthentication,
			}
		}
	}
	var uploadingMethod *shared.UploadingMethod
	if r.Configuration.UploadingMethod != nil {
		var awsS3Staging *shared.AWSS3Staging
		if r.Configuration.UploadingMethod.AWSS3Staging != nil {
			var accessKeyID string
			accessKeyID = r.Configuration.UploadingMethod.AWSS3Staging.AccessKeyID.ValueString()

			fileNamePattern := new(string)
			if !r.Configuration.UploadingMethod.AWSS3Staging.FileNamePattern.IsUnknown() && !r.Configuration.UploadingMethod.AWSS3Staging.FileNamePattern.IsNull() {
				*fileNamePattern = r.Configuration.UploadingMethod.AWSS3Staging.FileNamePattern.ValueString()
			} else {
				fileNamePattern = nil
			}
			purgeStagingData := new(bool)
			if !r.Configuration.UploadingMethod.AWSS3Staging.PurgeStagingData.IsUnknown() && !r.Configuration.UploadingMethod.AWSS3Staging.PurgeStagingData.IsNull() {
				*purgeStagingData = r.Configuration.UploadingMethod.AWSS3Staging.PurgeStagingData.ValueBool()
			} else {
				purgeStagingData = nil
			}
			var s3BucketName string
			s3BucketName = r.Configuration.UploadingMethod.AWSS3Staging.S3BucketName.ValueString()

			s3BucketPath := new(string)
			if !r.Configuration.UploadingMethod.AWSS3Staging.S3BucketPath.IsUnknown() && !r.Configuration.UploadingMethod.AWSS3Staging.S3BucketPath.IsNull() {
				*s3BucketPath = r.Configuration.UploadingMethod.AWSS3Staging.S3BucketPath.ValueString()
			} else {
				s3BucketPath = nil
			}
			s3BucketRegion := new(shared.DestinationRedshiftS3BucketRegion)
			if !r.Configuration.UploadingMethod.AWSS3Staging.S3BucketRegion.IsUnknown() && !r.Configuration.UploadingMethod.AWSS3Staging.S3BucketRegion.IsNull() {
				*s3BucketRegion = shared.DestinationRedshiftS3BucketRegion(r.Configuration.UploadingMethod.AWSS3Staging.S3BucketRegion.ValueString())
			} else {
				s3BucketRegion = nil
			}
			var secretAccessKey string
			secretAccessKey = r.Configuration.UploadingMethod.AWSS3Staging.SecretAccessKey.ValueString()

			awsS3Staging = &shared.AWSS3Staging{
				AccessKeyID:      accessKeyID,
				FileNamePattern:  fileNamePattern,
				PurgeStagingData: purgeStagingData,
				S3BucketName:     s3BucketName,
				S3BucketPath:     s3BucketPath,
				S3BucketRegion:   s3BucketRegion,
				SecretAccessKey:  secretAccessKey,
			}
		}
		if awsS3Staging != nil {
			uploadingMethod = &shared.UploadingMethod{
				AWSS3Staging: awsS3Staging,
			}
		}
	}
	var username string
	username = r.Configuration.Username.ValueString()

	configuration := shared.DestinationRedshift{
		Database:          database,
		DisableTypeDedupe: disableTypeDedupe,
		DropCascade:       dropCascade,
		Host:              host,
		JdbcURLParams:     jdbcURLParams,
		Password:          password,
		Port:              port,
		RawDataSchema:     rawDataSchema,
		Schema:            schema,
		TunnelMethod:      tunnelMethod,
		UploadingMethod:   uploadingMethod,
		Username:          username,
	}
	out := shared.DestinationRedshiftCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}

func (r *DestinationRedshiftResourceModel) 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 *DestinationRedshiftResourceModel) ToSharedDestinationRedshiftPutRequest() *shared.DestinationRedshiftPutRequest {
	var name string
	name = r.Name.ValueString()

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

	var database string
	database = r.Configuration.Database.ValueString()

	disableTypeDedupe := new(bool)
	if !r.Configuration.DisableTypeDedupe.IsUnknown() && !r.Configuration.DisableTypeDedupe.IsNull() {
		*disableTypeDedupe = r.Configuration.DisableTypeDedupe.ValueBool()
	} else {
		disableTypeDedupe = nil
	}
	dropCascade := new(bool)
	if !r.Configuration.DropCascade.IsUnknown() && !r.Configuration.DropCascade.IsNull() {
		*dropCascade = r.Configuration.DropCascade.ValueBool()
	} else {
		dropCascade = nil
	}
	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
	}
	var password string
	password = r.Configuration.Password.ValueString()

	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 tunnelMethod *shared.DestinationRedshiftUpdateSSHTunnelMethod
	if r.Configuration.TunnelMethod != nil {
		var destinationRedshiftUpdateNoTunnel *shared.DestinationRedshiftUpdateNoTunnel
		if r.Configuration.TunnelMethod.NoTunnel != nil {
			destinationRedshiftUpdateNoTunnel = &shared.DestinationRedshiftUpdateNoTunnel{}
		}
		if destinationRedshiftUpdateNoTunnel != nil {
			tunnelMethod = &shared.DestinationRedshiftUpdateSSHTunnelMethod{
				DestinationRedshiftUpdateNoTunnel: destinationRedshiftUpdateNoTunnel,
			}
		}
		var destinationRedshiftUpdateSSHKeyAuthentication *shared.DestinationRedshiftUpdateSSHKeyAuthentication
		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()

			destinationRedshiftUpdateSSHKeyAuthentication = &shared.DestinationRedshiftUpdateSSHKeyAuthentication{
				SSHKey:     sshKey,
				TunnelHost: tunnelHost,
				TunnelPort: tunnelPort,
				TunnelUser: tunnelUser,
			}
		}
		if destinationRedshiftUpdateSSHKeyAuthentication != nil {
			tunnelMethod = &shared.DestinationRedshiftUpdateSSHTunnelMethod{
				DestinationRedshiftUpdateSSHKeyAuthentication: destinationRedshiftUpdateSSHKeyAuthentication,
			}
		}
		var destinationRedshiftUpdatePasswordAuthentication *shared.DestinationRedshiftUpdatePasswordAuthentication
		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()

			destinationRedshiftUpdatePasswordAuthentication = &shared.DestinationRedshiftUpdatePasswordAuthentication{
				TunnelHost:         tunnelHost1,
				TunnelPort:         tunnelPort1,
				TunnelUser:         tunnelUser1,
				TunnelUserPassword: tunnelUserPassword,
			}
		}
		if destinationRedshiftUpdatePasswordAuthentication != nil {
			tunnelMethod = &shared.DestinationRedshiftUpdateSSHTunnelMethod{
				DestinationRedshiftUpdatePasswordAuthentication: destinationRedshiftUpdatePasswordAuthentication,
			}
		}
	}
	var uploadingMethod *shared.DestinationRedshiftUpdateUploadingMethod
	if r.Configuration.UploadingMethod != nil {
		var destinationRedshiftUpdateAWSS3Staging *shared.DestinationRedshiftUpdateAWSS3Staging
		if r.Configuration.UploadingMethod.AWSS3Staging != nil {
			var accessKeyID string
			accessKeyID = r.Configuration.UploadingMethod.AWSS3Staging.AccessKeyID.ValueString()

			fileNamePattern := new(string)
			if !r.Configuration.UploadingMethod.AWSS3Staging.FileNamePattern.IsUnknown() && !r.Configuration.UploadingMethod.AWSS3Staging.FileNamePattern.IsNull() {
				*fileNamePattern = r.Configuration.UploadingMethod.AWSS3Staging.FileNamePattern.ValueString()
			} else {
				fileNamePattern = nil
			}
			purgeStagingData := new(bool)
			if !r.Configuration.UploadingMethod.AWSS3Staging.PurgeStagingData.IsUnknown() && !r.Configuration.UploadingMethod.AWSS3Staging.PurgeStagingData.IsNull() {
				*purgeStagingData = r.Configuration.UploadingMethod.AWSS3Staging.PurgeStagingData.ValueBool()
			} else {
				purgeStagingData = nil
			}
			var s3BucketName string
			s3BucketName = r.Configuration.UploadingMethod.AWSS3Staging.S3BucketName.ValueString()

			s3BucketPath := new(string)
			if !r.Configuration.UploadingMethod.AWSS3Staging.S3BucketPath.IsUnknown() && !r.Configuration.UploadingMethod.AWSS3Staging.S3BucketPath.IsNull() {
				*s3BucketPath = r.Configuration.UploadingMethod.AWSS3Staging.S3BucketPath.ValueString()
			} else {
				s3BucketPath = nil
			}
			s3BucketRegion := new(shared.DestinationRedshiftUpdateS3BucketRegion)
			if !r.Configuration.UploadingMethod.AWSS3Staging.S3BucketRegion.IsUnknown() && !r.Configuration.UploadingMethod.AWSS3Staging.S3BucketRegion.IsNull() {
				*s3BucketRegion = shared.DestinationRedshiftUpdateS3BucketRegion(r.Configuration.UploadingMethod.AWSS3Staging.S3BucketRegion.ValueString())
			} else {
				s3BucketRegion = nil
			}
			var secretAccessKey string
			secretAccessKey = r.Configuration.UploadingMethod.AWSS3Staging.SecretAccessKey.ValueString()

			destinationRedshiftUpdateAWSS3Staging = &shared.DestinationRedshiftUpdateAWSS3Staging{
				AccessKeyID:      accessKeyID,
				FileNamePattern:  fileNamePattern,
				PurgeStagingData: purgeStagingData,
				S3BucketName:     s3BucketName,
				S3BucketPath:     s3BucketPath,
				S3BucketRegion:   s3BucketRegion,
				SecretAccessKey:  secretAccessKey,
			}
		}
		if destinationRedshiftUpdateAWSS3Staging != nil {
			uploadingMethod = &shared.DestinationRedshiftUpdateUploadingMethod{
				DestinationRedshiftUpdateAWSS3Staging: destinationRedshiftUpdateAWSS3Staging,
			}
		}
	}
	var username string
	username = r.Configuration.Username.ValueString()

	configuration := shared.DestinationRedshiftUpdate{
		Database:          database,
		DisableTypeDedupe: disableTypeDedupe,
		DropCascade:       dropCascade,
		Host:              host,
		JdbcURLParams:     jdbcURLParams,
		Password:          password,
		Port:              port,
		RawDataSchema:     rawDataSchema,
		Schema:            schema,
		TunnelMethod:      tunnelMethod,
		UploadingMethod:   uploadingMethod,
		Username:          username,
	}
	out := shared.DestinationRedshiftPutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
