// 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 *DestinationTeradataResourceModel) ToSharedDestinationTeradataCreateRequest() *shared.DestinationTeradataCreateRequest {
	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()

	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 logmech *shared.AuthorizationMechanism
	if r.Configuration.Logmech != nil {
		var td2 *shared.Td2
		if r.Configuration.Logmech.Td2 != nil {
			var password string
			password = r.Configuration.Logmech.Td2.Password.ValueString()

			var username string
			username = r.Configuration.Logmech.Td2.Username.ValueString()

			td2 = &shared.Td2{
				Password: password,
				Username: username,
			}
		}
		if td2 != nil {
			logmech = &shared.AuthorizationMechanism{
				Td2: td2,
			}
		}
		var ldap *shared.Ldap
		if r.Configuration.Logmech.Ldap != nil {
			var password1 string
			password1 = r.Configuration.Logmech.Ldap.Password.ValueString()

			var username1 string
			username1 = r.Configuration.Logmech.Ldap.Username.ValueString()

			ldap = &shared.Ldap{
				Password: password1,
				Username: username1,
			}
		}
		if ldap != nil {
			logmech = &shared.AuthorizationMechanism{
				Ldap: ldap,
			}
		}
	}
	queryBand := new(string)
	if !r.Configuration.QueryBand.IsUnknown() && !r.Configuration.QueryBand.IsNull() {
		*queryBand = r.Configuration.QueryBand.ValueString()
	} else {
		queryBand = 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
	}
	ssl := new(bool)
	if !r.Configuration.Ssl.IsUnknown() && !r.Configuration.Ssl.IsNull() {
		*ssl = r.Configuration.Ssl.ValueBool()
	} else {
		ssl = nil
	}
	var sslMode *shared.DestinationTeradataSSLModes
	if r.Configuration.SslMode != nil {
		var destinationTeradataDisable *shared.DestinationTeradataDisable
		if r.Configuration.SslMode.Disable != nil {
			destinationTeradataDisable = &shared.DestinationTeradataDisable{}
		}
		if destinationTeradataDisable != nil {
			sslMode = &shared.DestinationTeradataSSLModes{
				DestinationTeradataDisable: destinationTeradataDisable,
			}
		}
		var destinationTeradataAllow *shared.DestinationTeradataAllow
		if r.Configuration.SslMode.Allow != nil {
			destinationTeradataAllow = &shared.DestinationTeradataAllow{}
		}
		if destinationTeradataAllow != nil {
			sslMode = &shared.DestinationTeradataSSLModes{
				DestinationTeradataAllow: destinationTeradataAllow,
			}
		}
		var destinationTeradataPrefer *shared.DestinationTeradataPrefer
		if r.Configuration.SslMode.Prefer != nil {
			destinationTeradataPrefer = &shared.DestinationTeradataPrefer{}
		}
		if destinationTeradataPrefer != nil {
			sslMode = &shared.DestinationTeradataSSLModes{
				DestinationTeradataPrefer: destinationTeradataPrefer,
			}
		}
		var destinationTeradataRequire *shared.DestinationTeradataRequire
		if r.Configuration.SslMode.Require != nil {
			destinationTeradataRequire = &shared.DestinationTeradataRequire{}
		}
		if destinationTeradataRequire != nil {
			sslMode = &shared.DestinationTeradataSSLModes{
				DestinationTeradataRequire: destinationTeradataRequire,
			}
		}
		var destinationTeradataVerifyCa *shared.DestinationTeradataVerifyCa
		if r.Configuration.SslMode.VerifyCa != nil {
			var sslCaCertificate string
			sslCaCertificate = r.Configuration.SslMode.VerifyCa.SslCaCertificate.ValueString()

			destinationTeradataVerifyCa = &shared.DestinationTeradataVerifyCa{
				SslCaCertificate: sslCaCertificate,
			}
		}
		if destinationTeradataVerifyCa != nil {
			sslMode = &shared.DestinationTeradataSSLModes{
				DestinationTeradataVerifyCa: destinationTeradataVerifyCa,
			}
		}
		var destinationTeradataVerifyFull *shared.DestinationTeradataVerifyFull
		if r.Configuration.SslMode.VerifyFull != nil {
			var sslCaCertificate1 string
			sslCaCertificate1 = r.Configuration.SslMode.VerifyFull.SslCaCertificate.ValueString()

			destinationTeradataVerifyFull = &shared.DestinationTeradataVerifyFull{
				SslCaCertificate: sslCaCertificate1,
			}
		}
		if destinationTeradataVerifyFull != nil {
			sslMode = &shared.DestinationTeradataSSLModes{
				DestinationTeradataVerifyFull: destinationTeradataVerifyFull,
			}
		}
	}
	configuration := shared.DestinationTeradata{
		DisableTypeDedupe: disableTypeDedupe,
		DropCascade:       dropCascade,
		Host:              host,
		JdbcURLParams:     jdbcURLParams,
		Logmech:           logmech,
		QueryBand:         queryBand,
		RawDataSchema:     rawDataSchema,
		Schema:            schema,
		Ssl:               ssl,
		SslMode:           sslMode,
	}
	out := shared.DestinationTeradataCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}

func (r *DestinationTeradataResourceModel) 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 *DestinationTeradataResourceModel) ToSharedDestinationTeradataPutRequest() *shared.DestinationTeradataPutRequest {
	var name string
	name = r.Name.ValueString()

	var workspaceID string
	workspaceID = r.WorkspaceID.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 logmech *shared.DestinationTeradataUpdateAuthorizationMechanism
	if r.Configuration.Logmech != nil {
		var destinationTeradataUpdateTd2 *shared.DestinationTeradataUpdateTd2
		if r.Configuration.Logmech.Td2 != nil {
			var password string
			password = r.Configuration.Logmech.Td2.Password.ValueString()

			var username string
			username = r.Configuration.Logmech.Td2.Username.ValueString()

			destinationTeradataUpdateTd2 = &shared.DestinationTeradataUpdateTd2{
				Password: password,
				Username: username,
			}
		}
		if destinationTeradataUpdateTd2 != nil {
			logmech = &shared.DestinationTeradataUpdateAuthorizationMechanism{
				DestinationTeradataUpdateTd2: destinationTeradataUpdateTd2,
			}
		}
		var destinationTeradataUpdateLDAP *shared.DestinationTeradataUpdateLDAP
		if r.Configuration.Logmech.Ldap != nil {
			var password1 string
			password1 = r.Configuration.Logmech.Ldap.Password.ValueString()

			var username1 string
			username1 = r.Configuration.Logmech.Ldap.Username.ValueString()

			destinationTeradataUpdateLDAP = &shared.DestinationTeradataUpdateLDAP{
				Password: password1,
				Username: username1,
			}
		}
		if destinationTeradataUpdateLDAP != nil {
			logmech = &shared.DestinationTeradataUpdateAuthorizationMechanism{
				DestinationTeradataUpdateLDAP: destinationTeradataUpdateLDAP,
			}
		}
	}
	queryBand := new(string)
	if !r.Configuration.QueryBand.IsUnknown() && !r.Configuration.QueryBand.IsNull() {
		*queryBand = r.Configuration.QueryBand.ValueString()
	} else {
		queryBand = 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
	}
	ssl := new(bool)
	if !r.Configuration.Ssl.IsUnknown() && !r.Configuration.Ssl.IsNull() {
		*ssl = r.Configuration.Ssl.ValueBool()
	} else {
		ssl = nil
	}
	var sslMode *shared.DestinationTeradataUpdateSSLModes
	if r.Configuration.SslMode != nil {
		var destinationTeradataUpdateDisable *shared.DestinationTeradataUpdateDisable
		if r.Configuration.SslMode.Disable != nil {
			destinationTeradataUpdateDisable = &shared.DestinationTeradataUpdateDisable{}
		}
		if destinationTeradataUpdateDisable != nil {
			sslMode = &shared.DestinationTeradataUpdateSSLModes{
				DestinationTeradataUpdateDisable: destinationTeradataUpdateDisable,
			}
		}
		var destinationTeradataUpdateAllow *shared.DestinationTeradataUpdateAllow
		if r.Configuration.SslMode.Allow != nil {
			destinationTeradataUpdateAllow = &shared.DestinationTeradataUpdateAllow{}
		}
		if destinationTeradataUpdateAllow != nil {
			sslMode = &shared.DestinationTeradataUpdateSSLModes{
				DestinationTeradataUpdateAllow: destinationTeradataUpdateAllow,
			}
		}
		var destinationTeradataUpdatePrefer *shared.DestinationTeradataUpdatePrefer
		if r.Configuration.SslMode.Prefer != nil {
			destinationTeradataUpdatePrefer = &shared.DestinationTeradataUpdatePrefer{}
		}
		if destinationTeradataUpdatePrefer != nil {
			sslMode = &shared.DestinationTeradataUpdateSSLModes{
				DestinationTeradataUpdatePrefer: destinationTeradataUpdatePrefer,
			}
		}
		var destinationTeradataUpdateRequire *shared.DestinationTeradataUpdateRequire
		if r.Configuration.SslMode.Require != nil {
			destinationTeradataUpdateRequire = &shared.DestinationTeradataUpdateRequire{}
		}
		if destinationTeradataUpdateRequire != nil {
			sslMode = &shared.DestinationTeradataUpdateSSLModes{
				DestinationTeradataUpdateRequire: destinationTeradataUpdateRequire,
			}
		}
		var destinationTeradataUpdateVerifyCa *shared.DestinationTeradataUpdateVerifyCa
		if r.Configuration.SslMode.VerifyCa != nil {
			var sslCaCertificate string
			sslCaCertificate = r.Configuration.SslMode.VerifyCa.SslCaCertificate.ValueString()

			destinationTeradataUpdateVerifyCa = &shared.DestinationTeradataUpdateVerifyCa{
				SslCaCertificate: sslCaCertificate,
			}
		}
		if destinationTeradataUpdateVerifyCa != nil {
			sslMode = &shared.DestinationTeradataUpdateSSLModes{
				DestinationTeradataUpdateVerifyCa: destinationTeradataUpdateVerifyCa,
			}
		}
		var destinationTeradataUpdateVerifyFull *shared.DestinationTeradataUpdateVerifyFull
		if r.Configuration.SslMode.VerifyFull != nil {
			var sslCaCertificate1 string
			sslCaCertificate1 = r.Configuration.SslMode.VerifyFull.SslCaCertificate.ValueString()

			destinationTeradataUpdateVerifyFull = &shared.DestinationTeradataUpdateVerifyFull{
				SslCaCertificate: sslCaCertificate1,
			}
		}
		if destinationTeradataUpdateVerifyFull != nil {
			sslMode = &shared.DestinationTeradataUpdateSSLModes{
				DestinationTeradataUpdateVerifyFull: destinationTeradataUpdateVerifyFull,
			}
		}
	}
	configuration := shared.DestinationTeradataUpdate{
		DisableTypeDedupe: disableTypeDedupe,
		DropCascade:       dropCascade,
		Host:              host,
		JdbcURLParams:     jdbcURLParams,
		Logmech:           logmech,
		QueryBand:         queryBand,
		RawDataSchema:     rawDataSchema,
		Schema:            schema,
		Ssl:               ssl,
		SslMode:           sslMode,
	}
	out := shared.DestinationTeradataPutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
