// 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"
	"time"
)

func (r *SourceSftpBulkResourceModel) ToSharedSourceSftpBulkCreateRequest() *shared.SourceSftpBulkCreateRequest {
	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 credentials shared.SourceSftpBulkAuthentication
	var authenticateViaPassword *shared.AuthenticateViaPassword
	if r.Configuration.Credentials.AuthenticateViaPassword != nil {
		var password string
		password = r.Configuration.Credentials.AuthenticateViaPassword.Password.ValueString()

		authenticateViaPassword = &shared.AuthenticateViaPassword{
			Password: password,
		}
	}
	if authenticateViaPassword != nil {
		credentials = shared.SourceSftpBulkAuthentication{
			AuthenticateViaPassword: authenticateViaPassword,
		}
	}
	var authenticateViaPrivateKey *shared.AuthenticateViaPrivateKey
	if r.Configuration.Credentials.AuthenticateViaPrivateKey != nil {
		var privateKey string
		privateKey = r.Configuration.Credentials.AuthenticateViaPrivateKey.PrivateKey.ValueString()

		authenticateViaPrivateKey = &shared.AuthenticateViaPrivateKey{
			PrivateKey: privateKey,
		}
	}
	if authenticateViaPrivateKey != nil {
		credentials = shared.SourceSftpBulkAuthentication{
			AuthenticateViaPrivateKey: authenticateViaPrivateKey,
		}
	}
	var deliveryMethod *shared.SourceSftpBulkDeliveryMethod
	if r.Configuration.DeliveryMethod != nil {
		var sourceSftpBulkReplicateRecords *shared.SourceSftpBulkReplicateRecords
		if r.Configuration.DeliveryMethod.ReplicateRecords != nil {
			sourceSftpBulkReplicateRecords = &shared.SourceSftpBulkReplicateRecords{}
		}
		if sourceSftpBulkReplicateRecords != nil {
			deliveryMethod = &shared.SourceSftpBulkDeliveryMethod{
				SourceSftpBulkReplicateRecords: sourceSftpBulkReplicateRecords,
			}
		}
		var sourceSftpBulkCopyRawFiles *shared.SourceSftpBulkCopyRawFiles
		if r.Configuration.DeliveryMethod.CopyRawFiles != nil {
			preserveDirectoryStructure := new(bool)
			if !r.Configuration.DeliveryMethod.CopyRawFiles.PreserveDirectoryStructure.IsUnknown() && !r.Configuration.DeliveryMethod.CopyRawFiles.PreserveDirectoryStructure.IsNull() {
				*preserveDirectoryStructure = r.Configuration.DeliveryMethod.CopyRawFiles.PreserveDirectoryStructure.ValueBool()
			} else {
				preserveDirectoryStructure = nil
			}
			sourceSftpBulkCopyRawFiles = &shared.SourceSftpBulkCopyRawFiles{
				PreserveDirectoryStructure: preserveDirectoryStructure,
			}
		}
		if sourceSftpBulkCopyRawFiles != nil {
			deliveryMethod = &shared.SourceSftpBulkDeliveryMethod{
				SourceSftpBulkCopyRawFiles: sourceSftpBulkCopyRawFiles,
			}
		}
	}
	folderPath := new(string)
	if !r.Configuration.FolderPath.IsUnknown() && !r.Configuration.FolderPath.IsNull() {
		*folderPath = r.Configuration.FolderPath.ValueString()
	} else {
		folderPath = nil
	}
	var host string
	host = r.Configuration.Host.ValueString()

	port := new(int64)
	if !r.Configuration.Port.IsUnknown() && !r.Configuration.Port.IsNull() {
		*port = r.Configuration.Port.ValueInt64()
	} else {
		port = nil
	}
	startDate := new(time.Time)
	if !r.Configuration.StartDate.IsUnknown() && !r.Configuration.StartDate.IsNull() {
		*startDate, _ = time.Parse(time.RFC3339Nano, r.Configuration.StartDate.ValueString())
	} else {
		startDate = nil
	}
	var streams []shared.SourceSftpBulkFileBasedStreamConfig = []shared.SourceSftpBulkFileBasedStreamConfig{}
	for _, streamsItem := range r.Configuration.Streams {
		daysToSyncIfHistoryIsFull := new(int64)
		if !streamsItem.DaysToSyncIfHistoryIsFull.IsUnknown() && !streamsItem.DaysToSyncIfHistoryIsFull.IsNull() {
			*daysToSyncIfHistoryIsFull = streamsItem.DaysToSyncIfHistoryIsFull.ValueInt64()
		} else {
			daysToSyncIfHistoryIsFull = nil
		}
		var format shared.SourceSftpBulkFormat
		var sourceSftpBulkAvroFormat *shared.SourceSftpBulkAvroFormat
		if streamsItem.Format.AvroFormat != nil {
			doubleAsString := new(bool)
			if !streamsItem.Format.AvroFormat.DoubleAsString.IsUnknown() && !streamsItem.Format.AvroFormat.DoubleAsString.IsNull() {
				*doubleAsString = streamsItem.Format.AvroFormat.DoubleAsString.ValueBool()
			} else {
				doubleAsString = nil
			}
			sourceSftpBulkAvroFormat = &shared.SourceSftpBulkAvroFormat{
				DoubleAsString: doubleAsString,
			}
		}
		if sourceSftpBulkAvroFormat != nil {
			format = shared.SourceSftpBulkFormat{
				SourceSftpBulkAvroFormat: sourceSftpBulkAvroFormat,
			}
		}
		var sourceSftpBulkCSVFormat *shared.SourceSftpBulkCSVFormat
		if streamsItem.Format.CSVFormat != nil {
			delimiter := new(string)
			if !streamsItem.Format.CSVFormat.Delimiter.IsUnknown() && !streamsItem.Format.CSVFormat.Delimiter.IsNull() {
				*delimiter = streamsItem.Format.CSVFormat.Delimiter.ValueString()
			} else {
				delimiter = nil
			}
			doubleQuote := new(bool)
			if !streamsItem.Format.CSVFormat.DoubleQuote.IsUnknown() && !streamsItem.Format.CSVFormat.DoubleQuote.IsNull() {
				*doubleQuote = streamsItem.Format.CSVFormat.DoubleQuote.ValueBool()
			} else {
				doubleQuote = nil
			}
			encoding := new(string)
			if !streamsItem.Format.CSVFormat.Encoding.IsUnknown() && !streamsItem.Format.CSVFormat.Encoding.IsNull() {
				*encoding = streamsItem.Format.CSVFormat.Encoding.ValueString()
			} else {
				encoding = nil
			}
			escapeChar := new(string)
			if !streamsItem.Format.CSVFormat.EscapeChar.IsUnknown() && !streamsItem.Format.CSVFormat.EscapeChar.IsNull() {
				*escapeChar = streamsItem.Format.CSVFormat.EscapeChar.ValueString()
			} else {
				escapeChar = nil
			}
			var falseValues []string = []string{}
			for _, falseValuesItem := range streamsItem.Format.CSVFormat.FalseValues {
				falseValues = append(falseValues, falseValuesItem.ValueString())
			}
			var headerDefinition *shared.SourceSftpBulkCSVHeaderDefinition
			if streamsItem.Format.CSVFormat.HeaderDefinition != nil {
				var sourceSftpBulkFromCSV *shared.SourceSftpBulkFromCSV
				if streamsItem.Format.CSVFormat.HeaderDefinition.FromCSV != nil {
					sourceSftpBulkFromCSV = &shared.SourceSftpBulkFromCSV{}
				}
				if sourceSftpBulkFromCSV != nil {
					headerDefinition = &shared.SourceSftpBulkCSVHeaderDefinition{
						SourceSftpBulkFromCSV: sourceSftpBulkFromCSV,
					}
				}
				var sourceSftpBulkAutogenerated *shared.SourceSftpBulkAutogenerated
				if streamsItem.Format.CSVFormat.HeaderDefinition.Autogenerated != nil {
					sourceSftpBulkAutogenerated = &shared.SourceSftpBulkAutogenerated{}
				}
				if sourceSftpBulkAutogenerated != nil {
					headerDefinition = &shared.SourceSftpBulkCSVHeaderDefinition{
						SourceSftpBulkAutogenerated: sourceSftpBulkAutogenerated,
					}
				}
				var sourceSftpBulkUserProvided *shared.SourceSftpBulkUserProvided
				if streamsItem.Format.CSVFormat.HeaderDefinition.UserProvided != nil {
					var columnNames []string = []string{}
					for _, columnNamesItem := range streamsItem.Format.CSVFormat.HeaderDefinition.UserProvided.ColumnNames {
						columnNames = append(columnNames, columnNamesItem.ValueString())
					}
					sourceSftpBulkUserProvided = &shared.SourceSftpBulkUserProvided{
						ColumnNames: columnNames,
					}
				}
				if sourceSftpBulkUserProvided != nil {
					headerDefinition = &shared.SourceSftpBulkCSVHeaderDefinition{
						SourceSftpBulkUserProvided: sourceSftpBulkUserProvided,
					}
				}
			}
			ignoreErrorsOnFieldsMismatch := new(bool)
			if !streamsItem.Format.CSVFormat.IgnoreErrorsOnFieldsMismatch.IsUnknown() && !streamsItem.Format.CSVFormat.IgnoreErrorsOnFieldsMismatch.IsNull() {
				*ignoreErrorsOnFieldsMismatch = streamsItem.Format.CSVFormat.IgnoreErrorsOnFieldsMismatch.ValueBool()
			} else {
				ignoreErrorsOnFieldsMismatch = nil
			}
			var nullValues []string = []string{}
			for _, nullValuesItem := range streamsItem.Format.CSVFormat.NullValues {
				nullValues = append(nullValues, nullValuesItem.ValueString())
			}
			quoteChar := new(string)
			if !streamsItem.Format.CSVFormat.QuoteChar.IsUnknown() && !streamsItem.Format.CSVFormat.QuoteChar.IsNull() {
				*quoteChar = streamsItem.Format.CSVFormat.QuoteChar.ValueString()
			} else {
				quoteChar = nil
			}
			skipRowsAfterHeader := new(int64)
			if !streamsItem.Format.CSVFormat.SkipRowsAfterHeader.IsUnknown() && !streamsItem.Format.CSVFormat.SkipRowsAfterHeader.IsNull() {
				*skipRowsAfterHeader = streamsItem.Format.CSVFormat.SkipRowsAfterHeader.ValueInt64()
			} else {
				skipRowsAfterHeader = nil
			}
			skipRowsBeforeHeader := new(int64)
			if !streamsItem.Format.CSVFormat.SkipRowsBeforeHeader.IsUnknown() && !streamsItem.Format.CSVFormat.SkipRowsBeforeHeader.IsNull() {
				*skipRowsBeforeHeader = streamsItem.Format.CSVFormat.SkipRowsBeforeHeader.ValueInt64()
			} else {
				skipRowsBeforeHeader = nil
			}
			stringsCanBeNull := new(bool)
			if !streamsItem.Format.CSVFormat.StringsCanBeNull.IsUnknown() && !streamsItem.Format.CSVFormat.StringsCanBeNull.IsNull() {
				*stringsCanBeNull = streamsItem.Format.CSVFormat.StringsCanBeNull.ValueBool()
			} else {
				stringsCanBeNull = nil
			}
			var trueValues []string = []string{}
			for _, trueValuesItem := range streamsItem.Format.CSVFormat.TrueValues {
				trueValues = append(trueValues, trueValuesItem.ValueString())
			}
			sourceSftpBulkCSVFormat = &shared.SourceSftpBulkCSVFormat{
				Delimiter:                    delimiter,
				DoubleQuote:                  doubleQuote,
				Encoding:                     encoding,
				EscapeChar:                   escapeChar,
				FalseValues:                  falseValues,
				HeaderDefinition:             headerDefinition,
				IgnoreErrorsOnFieldsMismatch: ignoreErrorsOnFieldsMismatch,
				NullValues:                   nullValues,
				QuoteChar:                    quoteChar,
				SkipRowsAfterHeader:          skipRowsAfterHeader,
				SkipRowsBeforeHeader:         skipRowsBeforeHeader,
				StringsCanBeNull:             stringsCanBeNull,
				TrueValues:                   trueValues,
			}
		}
		if sourceSftpBulkCSVFormat != nil {
			format = shared.SourceSftpBulkFormat{
				SourceSftpBulkCSVFormat: sourceSftpBulkCSVFormat,
			}
		}
		var sourceSftpBulkJsonlFormat *shared.SourceSftpBulkJsonlFormat
		if streamsItem.Format.JsonlFormat != nil {
			sourceSftpBulkJsonlFormat = &shared.SourceSftpBulkJsonlFormat{}
		}
		if sourceSftpBulkJsonlFormat != nil {
			format = shared.SourceSftpBulkFormat{
				SourceSftpBulkJsonlFormat: sourceSftpBulkJsonlFormat,
			}
		}
		var sourceSftpBulkParquetFormat *shared.SourceSftpBulkParquetFormat
		if streamsItem.Format.ParquetFormat != nil {
			decimalAsFloat := new(bool)
			if !streamsItem.Format.ParquetFormat.DecimalAsFloat.IsUnknown() && !streamsItem.Format.ParquetFormat.DecimalAsFloat.IsNull() {
				*decimalAsFloat = streamsItem.Format.ParquetFormat.DecimalAsFloat.ValueBool()
			} else {
				decimalAsFloat = nil
			}
			sourceSftpBulkParquetFormat = &shared.SourceSftpBulkParquetFormat{
				DecimalAsFloat: decimalAsFloat,
			}
		}
		if sourceSftpBulkParquetFormat != nil {
			format = shared.SourceSftpBulkFormat{
				SourceSftpBulkParquetFormat: sourceSftpBulkParquetFormat,
			}
		}
		var sourceSftpBulkUnstructuredDocumentFormat *shared.SourceSftpBulkUnstructuredDocumentFormat
		if streamsItem.Format.UnstructuredDocumentFormat != nil {
			var processing *shared.SourceSftpBulkProcessing
			if streamsItem.Format.UnstructuredDocumentFormat.Processing != nil {
				var sourceSftpBulkLocal *shared.SourceSftpBulkLocal
				if streamsItem.Format.UnstructuredDocumentFormat.Processing.Local != nil {
					sourceSftpBulkLocal = &shared.SourceSftpBulkLocal{}
				}
				if sourceSftpBulkLocal != nil {
					processing = &shared.SourceSftpBulkProcessing{
						SourceSftpBulkLocal: sourceSftpBulkLocal,
					}
				}
				var sourceSftpBulkViaAPI *shared.SourceSftpBulkViaAPI
				if streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI != nil {
					apiKey := new(string)
					if !streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIKey.IsUnknown() && !streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIKey.IsNull() {
						*apiKey = streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIKey.ValueString()
					} else {
						apiKey = nil
					}
					apiURL := new(string)
					if !streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIURL.IsUnknown() && !streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIURL.IsNull() {
						*apiURL = streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIURL.ValueString()
					} else {
						apiURL = nil
					}
					var parameters []shared.SourceSftpBulkAPIParameterConfigModel = []shared.SourceSftpBulkAPIParameterConfigModel{}
					for _, parametersItem := range streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.Parameters {
						var name1 string
						name1 = parametersItem.Name.ValueString()

						var value string
						value = parametersItem.Value.ValueString()

						parameters = append(parameters, shared.SourceSftpBulkAPIParameterConfigModel{
							Name:  name1,
							Value: value,
						})
					}
					sourceSftpBulkViaAPI = &shared.SourceSftpBulkViaAPI{
						APIKey:     apiKey,
						APIURL:     apiURL,
						Parameters: parameters,
					}
				}
				if sourceSftpBulkViaAPI != nil {
					processing = &shared.SourceSftpBulkProcessing{
						SourceSftpBulkViaAPI: sourceSftpBulkViaAPI,
					}
				}
			}
			skipUnprocessableFiles := new(bool)
			if !streamsItem.Format.UnstructuredDocumentFormat.SkipUnprocessableFiles.IsUnknown() && !streamsItem.Format.UnstructuredDocumentFormat.SkipUnprocessableFiles.IsNull() {
				*skipUnprocessableFiles = streamsItem.Format.UnstructuredDocumentFormat.SkipUnprocessableFiles.ValueBool()
			} else {
				skipUnprocessableFiles = nil
			}
			strategy := new(shared.SourceSftpBulkParsingStrategy)
			if !streamsItem.Format.UnstructuredDocumentFormat.Strategy.IsUnknown() && !streamsItem.Format.UnstructuredDocumentFormat.Strategy.IsNull() {
				*strategy = shared.SourceSftpBulkParsingStrategy(streamsItem.Format.UnstructuredDocumentFormat.Strategy.ValueString())
			} else {
				strategy = nil
			}
			sourceSftpBulkUnstructuredDocumentFormat = &shared.SourceSftpBulkUnstructuredDocumentFormat{
				Processing:             processing,
				SkipUnprocessableFiles: skipUnprocessableFiles,
				Strategy:               strategy,
			}
		}
		if sourceSftpBulkUnstructuredDocumentFormat != nil {
			format = shared.SourceSftpBulkFormat{
				SourceSftpBulkUnstructuredDocumentFormat: sourceSftpBulkUnstructuredDocumentFormat,
			}
		}
		var sourceSftpBulkExcelFormat *shared.SourceSftpBulkExcelFormat
		if streamsItem.Format.ExcelFormat != nil {
			sourceSftpBulkExcelFormat = &shared.SourceSftpBulkExcelFormat{}
		}
		if sourceSftpBulkExcelFormat != nil {
			format = shared.SourceSftpBulkFormat{
				SourceSftpBulkExcelFormat: sourceSftpBulkExcelFormat,
			}
		}
		var globs []string = []string{}
		for _, globsItem := range streamsItem.Globs {
			globs = append(globs, globsItem.ValueString())
		}
		inputSchema := new(string)
		if !streamsItem.InputSchema.IsUnknown() && !streamsItem.InputSchema.IsNull() {
			*inputSchema = streamsItem.InputSchema.ValueString()
		} else {
			inputSchema = nil
		}
		var name2 string
		name2 = streamsItem.Name.ValueString()

		recentNFilesToReadForSchemaDiscovery := new(int64)
		if !streamsItem.RecentNFilesToReadForSchemaDiscovery.IsUnknown() && !streamsItem.RecentNFilesToReadForSchemaDiscovery.IsNull() {
			*recentNFilesToReadForSchemaDiscovery = streamsItem.RecentNFilesToReadForSchemaDiscovery.ValueInt64()
		} else {
			recentNFilesToReadForSchemaDiscovery = nil
		}
		schemaless := new(bool)
		if !streamsItem.Schemaless.IsUnknown() && !streamsItem.Schemaless.IsNull() {
			*schemaless = streamsItem.Schemaless.ValueBool()
		} else {
			schemaless = nil
		}
		validationPolicy := new(shared.SourceSftpBulkValidationPolicy)
		if !streamsItem.ValidationPolicy.IsUnknown() && !streamsItem.ValidationPolicy.IsNull() {
			*validationPolicy = shared.SourceSftpBulkValidationPolicy(streamsItem.ValidationPolicy.ValueString())
		} else {
			validationPolicy = nil
		}
		streams = append(streams, shared.SourceSftpBulkFileBasedStreamConfig{
			DaysToSyncIfHistoryIsFull:            daysToSyncIfHistoryIsFull,
			Format:                               format,
			Globs:                                globs,
			InputSchema:                          inputSchema,
			Name:                                 name2,
			RecentNFilesToReadForSchemaDiscovery: recentNFilesToReadForSchemaDiscovery,
			Schemaless:                           schemaless,
			ValidationPolicy:                     validationPolicy,
		})
	}
	var username string
	username = r.Configuration.Username.ValueString()

	configuration := shared.SourceSftpBulk{
		Credentials:    credentials,
		DeliveryMethod: deliveryMethod,
		FolderPath:     folderPath,
		Host:           host,
		Port:           port,
		StartDate:      startDate,
		Streams:        streams,
		Username:       username,
	}
	secretID := new(string)
	if !r.SecretID.IsUnknown() && !r.SecretID.IsNull() {
		*secretID = r.SecretID.ValueString()
	} else {
		secretID = nil
	}
	out := shared.SourceSftpBulkCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
		SecretID:      secretID,
	}
	return &out
}

func (r *SourceSftpBulkResourceModel) 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 *SourceSftpBulkResourceModel) ToSharedSourceSftpBulkPutRequest() *shared.SourceSftpBulkPutRequest {
	var name string
	name = r.Name.ValueString()

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

	var credentials shared.SourceSftpBulkUpdateAuthentication
	var sourceSftpBulkUpdateAuthenticateViaPassword *shared.SourceSftpBulkUpdateAuthenticateViaPassword
	if r.Configuration.Credentials.AuthenticateViaPassword != nil {
		var password string
		password = r.Configuration.Credentials.AuthenticateViaPassword.Password.ValueString()

		sourceSftpBulkUpdateAuthenticateViaPassword = &shared.SourceSftpBulkUpdateAuthenticateViaPassword{
			Password: password,
		}
	}
	if sourceSftpBulkUpdateAuthenticateViaPassword != nil {
		credentials = shared.SourceSftpBulkUpdateAuthentication{
			SourceSftpBulkUpdateAuthenticateViaPassword: sourceSftpBulkUpdateAuthenticateViaPassword,
		}
	}
	var sourceSftpBulkUpdateAuthenticateViaPrivateKey *shared.SourceSftpBulkUpdateAuthenticateViaPrivateKey
	if r.Configuration.Credentials.AuthenticateViaPrivateKey != nil {
		var privateKey string
		privateKey = r.Configuration.Credentials.AuthenticateViaPrivateKey.PrivateKey.ValueString()

		sourceSftpBulkUpdateAuthenticateViaPrivateKey = &shared.SourceSftpBulkUpdateAuthenticateViaPrivateKey{
			PrivateKey: privateKey,
		}
	}
	if sourceSftpBulkUpdateAuthenticateViaPrivateKey != nil {
		credentials = shared.SourceSftpBulkUpdateAuthentication{
			SourceSftpBulkUpdateAuthenticateViaPrivateKey: sourceSftpBulkUpdateAuthenticateViaPrivateKey,
		}
	}
	var deliveryMethod *shared.SourceSftpBulkUpdateDeliveryMethod
	if r.Configuration.DeliveryMethod != nil {
		var sourceSftpBulkUpdateReplicateRecords *shared.SourceSftpBulkUpdateReplicateRecords
		if r.Configuration.DeliveryMethod.ReplicateRecords != nil {
			sourceSftpBulkUpdateReplicateRecords = &shared.SourceSftpBulkUpdateReplicateRecords{}
		}
		if sourceSftpBulkUpdateReplicateRecords != nil {
			deliveryMethod = &shared.SourceSftpBulkUpdateDeliveryMethod{
				SourceSftpBulkUpdateReplicateRecords: sourceSftpBulkUpdateReplicateRecords,
			}
		}
		var sourceSftpBulkUpdateCopyRawFiles *shared.SourceSftpBulkUpdateCopyRawFiles
		if r.Configuration.DeliveryMethod.CopyRawFiles != nil {
			preserveDirectoryStructure := new(bool)
			if !r.Configuration.DeliveryMethod.CopyRawFiles.PreserveDirectoryStructure.IsUnknown() && !r.Configuration.DeliveryMethod.CopyRawFiles.PreserveDirectoryStructure.IsNull() {
				*preserveDirectoryStructure = r.Configuration.DeliveryMethod.CopyRawFiles.PreserveDirectoryStructure.ValueBool()
			} else {
				preserveDirectoryStructure = nil
			}
			sourceSftpBulkUpdateCopyRawFiles = &shared.SourceSftpBulkUpdateCopyRawFiles{
				PreserveDirectoryStructure: preserveDirectoryStructure,
			}
		}
		if sourceSftpBulkUpdateCopyRawFiles != nil {
			deliveryMethod = &shared.SourceSftpBulkUpdateDeliveryMethod{
				SourceSftpBulkUpdateCopyRawFiles: sourceSftpBulkUpdateCopyRawFiles,
			}
		}
	}
	folderPath := new(string)
	if !r.Configuration.FolderPath.IsUnknown() && !r.Configuration.FolderPath.IsNull() {
		*folderPath = r.Configuration.FolderPath.ValueString()
	} else {
		folderPath = nil
	}
	var host string
	host = r.Configuration.Host.ValueString()

	port := new(int64)
	if !r.Configuration.Port.IsUnknown() && !r.Configuration.Port.IsNull() {
		*port = r.Configuration.Port.ValueInt64()
	} else {
		port = nil
	}
	startDate := new(time.Time)
	if !r.Configuration.StartDate.IsUnknown() && !r.Configuration.StartDate.IsNull() {
		*startDate, _ = time.Parse(time.RFC3339Nano, r.Configuration.StartDate.ValueString())
	} else {
		startDate = nil
	}
	var streams []shared.SourceSftpBulkUpdateFileBasedStreamConfig = []shared.SourceSftpBulkUpdateFileBasedStreamConfig{}
	for _, streamsItem := range r.Configuration.Streams {
		daysToSyncIfHistoryIsFull := new(int64)
		if !streamsItem.DaysToSyncIfHistoryIsFull.IsUnknown() && !streamsItem.DaysToSyncIfHistoryIsFull.IsNull() {
			*daysToSyncIfHistoryIsFull = streamsItem.DaysToSyncIfHistoryIsFull.ValueInt64()
		} else {
			daysToSyncIfHistoryIsFull = nil
		}
		var format shared.SourceSftpBulkUpdateFormat
		var sourceSftpBulkUpdateAvroFormat *shared.SourceSftpBulkUpdateAvroFormat
		if streamsItem.Format.AvroFormat != nil {
			doubleAsString := new(bool)
			if !streamsItem.Format.AvroFormat.DoubleAsString.IsUnknown() && !streamsItem.Format.AvroFormat.DoubleAsString.IsNull() {
				*doubleAsString = streamsItem.Format.AvroFormat.DoubleAsString.ValueBool()
			} else {
				doubleAsString = nil
			}
			sourceSftpBulkUpdateAvroFormat = &shared.SourceSftpBulkUpdateAvroFormat{
				DoubleAsString: doubleAsString,
			}
		}
		if sourceSftpBulkUpdateAvroFormat != nil {
			format = shared.SourceSftpBulkUpdateFormat{
				SourceSftpBulkUpdateAvroFormat: sourceSftpBulkUpdateAvroFormat,
			}
		}
		var sourceSftpBulkUpdateCSVFormat *shared.SourceSftpBulkUpdateCSVFormat
		if streamsItem.Format.CSVFormat != nil {
			delimiter := new(string)
			if !streamsItem.Format.CSVFormat.Delimiter.IsUnknown() && !streamsItem.Format.CSVFormat.Delimiter.IsNull() {
				*delimiter = streamsItem.Format.CSVFormat.Delimiter.ValueString()
			} else {
				delimiter = nil
			}
			doubleQuote := new(bool)
			if !streamsItem.Format.CSVFormat.DoubleQuote.IsUnknown() && !streamsItem.Format.CSVFormat.DoubleQuote.IsNull() {
				*doubleQuote = streamsItem.Format.CSVFormat.DoubleQuote.ValueBool()
			} else {
				doubleQuote = nil
			}
			encoding := new(string)
			if !streamsItem.Format.CSVFormat.Encoding.IsUnknown() && !streamsItem.Format.CSVFormat.Encoding.IsNull() {
				*encoding = streamsItem.Format.CSVFormat.Encoding.ValueString()
			} else {
				encoding = nil
			}
			escapeChar := new(string)
			if !streamsItem.Format.CSVFormat.EscapeChar.IsUnknown() && !streamsItem.Format.CSVFormat.EscapeChar.IsNull() {
				*escapeChar = streamsItem.Format.CSVFormat.EscapeChar.ValueString()
			} else {
				escapeChar = nil
			}
			var falseValues []string = []string{}
			for _, falseValuesItem := range streamsItem.Format.CSVFormat.FalseValues {
				falseValues = append(falseValues, falseValuesItem.ValueString())
			}
			var headerDefinition *shared.SourceSftpBulkUpdateCSVHeaderDefinition
			if streamsItem.Format.CSVFormat.HeaderDefinition != nil {
				var sourceSftpBulkUpdateFromCSV *shared.SourceSftpBulkUpdateFromCSV
				if streamsItem.Format.CSVFormat.HeaderDefinition.FromCSV != nil {
					sourceSftpBulkUpdateFromCSV = &shared.SourceSftpBulkUpdateFromCSV{}
				}
				if sourceSftpBulkUpdateFromCSV != nil {
					headerDefinition = &shared.SourceSftpBulkUpdateCSVHeaderDefinition{
						SourceSftpBulkUpdateFromCSV: sourceSftpBulkUpdateFromCSV,
					}
				}
				var sourceSftpBulkUpdateAutogenerated *shared.SourceSftpBulkUpdateAutogenerated
				if streamsItem.Format.CSVFormat.HeaderDefinition.Autogenerated != nil {
					sourceSftpBulkUpdateAutogenerated = &shared.SourceSftpBulkUpdateAutogenerated{}
				}
				if sourceSftpBulkUpdateAutogenerated != nil {
					headerDefinition = &shared.SourceSftpBulkUpdateCSVHeaderDefinition{
						SourceSftpBulkUpdateAutogenerated: sourceSftpBulkUpdateAutogenerated,
					}
				}
				var sourceSftpBulkUpdateUserProvided *shared.SourceSftpBulkUpdateUserProvided
				if streamsItem.Format.CSVFormat.HeaderDefinition.UserProvided != nil {
					var columnNames []string = []string{}
					for _, columnNamesItem := range streamsItem.Format.CSVFormat.HeaderDefinition.UserProvided.ColumnNames {
						columnNames = append(columnNames, columnNamesItem.ValueString())
					}
					sourceSftpBulkUpdateUserProvided = &shared.SourceSftpBulkUpdateUserProvided{
						ColumnNames: columnNames,
					}
				}
				if sourceSftpBulkUpdateUserProvided != nil {
					headerDefinition = &shared.SourceSftpBulkUpdateCSVHeaderDefinition{
						SourceSftpBulkUpdateUserProvided: sourceSftpBulkUpdateUserProvided,
					}
				}
			}
			ignoreErrorsOnFieldsMismatch := new(bool)
			if !streamsItem.Format.CSVFormat.IgnoreErrorsOnFieldsMismatch.IsUnknown() && !streamsItem.Format.CSVFormat.IgnoreErrorsOnFieldsMismatch.IsNull() {
				*ignoreErrorsOnFieldsMismatch = streamsItem.Format.CSVFormat.IgnoreErrorsOnFieldsMismatch.ValueBool()
			} else {
				ignoreErrorsOnFieldsMismatch = nil
			}
			var nullValues []string = []string{}
			for _, nullValuesItem := range streamsItem.Format.CSVFormat.NullValues {
				nullValues = append(nullValues, nullValuesItem.ValueString())
			}
			quoteChar := new(string)
			if !streamsItem.Format.CSVFormat.QuoteChar.IsUnknown() && !streamsItem.Format.CSVFormat.QuoteChar.IsNull() {
				*quoteChar = streamsItem.Format.CSVFormat.QuoteChar.ValueString()
			} else {
				quoteChar = nil
			}
			skipRowsAfterHeader := new(int64)
			if !streamsItem.Format.CSVFormat.SkipRowsAfterHeader.IsUnknown() && !streamsItem.Format.CSVFormat.SkipRowsAfterHeader.IsNull() {
				*skipRowsAfterHeader = streamsItem.Format.CSVFormat.SkipRowsAfterHeader.ValueInt64()
			} else {
				skipRowsAfterHeader = nil
			}
			skipRowsBeforeHeader := new(int64)
			if !streamsItem.Format.CSVFormat.SkipRowsBeforeHeader.IsUnknown() && !streamsItem.Format.CSVFormat.SkipRowsBeforeHeader.IsNull() {
				*skipRowsBeforeHeader = streamsItem.Format.CSVFormat.SkipRowsBeforeHeader.ValueInt64()
			} else {
				skipRowsBeforeHeader = nil
			}
			stringsCanBeNull := new(bool)
			if !streamsItem.Format.CSVFormat.StringsCanBeNull.IsUnknown() && !streamsItem.Format.CSVFormat.StringsCanBeNull.IsNull() {
				*stringsCanBeNull = streamsItem.Format.CSVFormat.StringsCanBeNull.ValueBool()
			} else {
				stringsCanBeNull = nil
			}
			var trueValues []string = []string{}
			for _, trueValuesItem := range streamsItem.Format.CSVFormat.TrueValues {
				trueValues = append(trueValues, trueValuesItem.ValueString())
			}
			sourceSftpBulkUpdateCSVFormat = &shared.SourceSftpBulkUpdateCSVFormat{
				Delimiter:                    delimiter,
				DoubleQuote:                  doubleQuote,
				Encoding:                     encoding,
				EscapeChar:                   escapeChar,
				FalseValues:                  falseValues,
				HeaderDefinition:             headerDefinition,
				IgnoreErrorsOnFieldsMismatch: ignoreErrorsOnFieldsMismatch,
				NullValues:                   nullValues,
				QuoteChar:                    quoteChar,
				SkipRowsAfterHeader:          skipRowsAfterHeader,
				SkipRowsBeforeHeader:         skipRowsBeforeHeader,
				StringsCanBeNull:             stringsCanBeNull,
				TrueValues:                   trueValues,
			}
		}
		if sourceSftpBulkUpdateCSVFormat != nil {
			format = shared.SourceSftpBulkUpdateFormat{
				SourceSftpBulkUpdateCSVFormat: sourceSftpBulkUpdateCSVFormat,
			}
		}
		var sourceSftpBulkUpdateJsonlFormat *shared.SourceSftpBulkUpdateJsonlFormat
		if streamsItem.Format.JsonlFormat != nil {
			sourceSftpBulkUpdateJsonlFormat = &shared.SourceSftpBulkUpdateJsonlFormat{}
		}
		if sourceSftpBulkUpdateJsonlFormat != nil {
			format = shared.SourceSftpBulkUpdateFormat{
				SourceSftpBulkUpdateJsonlFormat: sourceSftpBulkUpdateJsonlFormat,
			}
		}
		var sourceSftpBulkUpdateParquetFormat *shared.SourceSftpBulkUpdateParquetFormat
		if streamsItem.Format.ParquetFormat != nil {
			decimalAsFloat := new(bool)
			if !streamsItem.Format.ParquetFormat.DecimalAsFloat.IsUnknown() && !streamsItem.Format.ParquetFormat.DecimalAsFloat.IsNull() {
				*decimalAsFloat = streamsItem.Format.ParquetFormat.DecimalAsFloat.ValueBool()
			} else {
				decimalAsFloat = nil
			}
			sourceSftpBulkUpdateParquetFormat = &shared.SourceSftpBulkUpdateParquetFormat{
				DecimalAsFloat: decimalAsFloat,
			}
		}
		if sourceSftpBulkUpdateParquetFormat != nil {
			format = shared.SourceSftpBulkUpdateFormat{
				SourceSftpBulkUpdateParquetFormat: sourceSftpBulkUpdateParquetFormat,
			}
		}
		var sourceSftpBulkUpdateUnstructuredDocumentFormat *shared.SourceSftpBulkUpdateUnstructuredDocumentFormat
		if streamsItem.Format.UnstructuredDocumentFormat != nil {
			var processing *shared.SourceSftpBulkUpdateProcessing
			if streamsItem.Format.UnstructuredDocumentFormat.Processing != nil {
				var sourceSftpBulkUpdateLocal *shared.SourceSftpBulkUpdateLocal
				if streamsItem.Format.UnstructuredDocumentFormat.Processing.Local != nil {
					sourceSftpBulkUpdateLocal = &shared.SourceSftpBulkUpdateLocal{}
				}
				if sourceSftpBulkUpdateLocal != nil {
					processing = &shared.SourceSftpBulkUpdateProcessing{
						SourceSftpBulkUpdateLocal: sourceSftpBulkUpdateLocal,
					}
				}
				var sourceSftpBulkUpdateViaAPI *shared.SourceSftpBulkUpdateViaAPI
				if streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI != nil {
					apiKey := new(string)
					if !streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIKey.IsUnknown() && !streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIKey.IsNull() {
						*apiKey = streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIKey.ValueString()
					} else {
						apiKey = nil
					}
					apiURL := new(string)
					if !streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIURL.IsUnknown() && !streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIURL.IsNull() {
						*apiURL = streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.APIURL.ValueString()
					} else {
						apiURL = nil
					}
					var parameters []shared.SourceSftpBulkUpdateAPIParameterConfigModel = []shared.SourceSftpBulkUpdateAPIParameterConfigModel{}
					for _, parametersItem := range streamsItem.Format.UnstructuredDocumentFormat.Processing.ViaAPI.Parameters {
						var name1 string
						name1 = parametersItem.Name.ValueString()

						var value string
						value = parametersItem.Value.ValueString()

						parameters = append(parameters, shared.SourceSftpBulkUpdateAPIParameterConfigModel{
							Name:  name1,
							Value: value,
						})
					}
					sourceSftpBulkUpdateViaAPI = &shared.SourceSftpBulkUpdateViaAPI{
						APIKey:     apiKey,
						APIURL:     apiURL,
						Parameters: parameters,
					}
				}
				if sourceSftpBulkUpdateViaAPI != nil {
					processing = &shared.SourceSftpBulkUpdateProcessing{
						SourceSftpBulkUpdateViaAPI: sourceSftpBulkUpdateViaAPI,
					}
				}
			}
			skipUnprocessableFiles := new(bool)
			if !streamsItem.Format.UnstructuredDocumentFormat.SkipUnprocessableFiles.IsUnknown() && !streamsItem.Format.UnstructuredDocumentFormat.SkipUnprocessableFiles.IsNull() {
				*skipUnprocessableFiles = streamsItem.Format.UnstructuredDocumentFormat.SkipUnprocessableFiles.ValueBool()
			} else {
				skipUnprocessableFiles = nil
			}
			strategy := new(shared.SourceSftpBulkUpdateParsingStrategy)
			if !streamsItem.Format.UnstructuredDocumentFormat.Strategy.IsUnknown() && !streamsItem.Format.UnstructuredDocumentFormat.Strategy.IsNull() {
				*strategy = shared.SourceSftpBulkUpdateParsingStrategy(streamsItem.Format.UnstructuredDocumentFormat.Strategy.ValueString())
			} else {
				strategy = nil
			}
			sourceSftpBulkUpdateUnstructuredDocumentFormat = &shared.SourceSftpBulkUpdateUnstructuredDocumentFormat{
				Processing:             processing,
				SkipUnprocessableFiles: skipUnprocessableFiles,
				Strategy:               strategy,
			}
		}
		if sourceSftpBulkUpdateUnstructuredDocumentFormat != nil {
			format = shared.SourceSftpBulkUpdateFormat{
				SourceSftpBulkUpdateUnstructuredDocumentFormat: sourceSftpBulkUpdateUnstructuredDocumentFormat,
			}
		}
		var sourceSftpBulkUpdateExcelFormat *shared.SourceSftpBulkUpdateExcelFormat
		if streamsItem.Format.ExcelFormat != nil {
			sourceSftpBulkUpdateExcelFormat = &shared.SourceSftpBulkUpdateExcelFormat{}
		}
		if sourceSftpBulkUpdateExcelFormat != nil {
			format = shared.SourceSftpBulkUpdateFormat{
				SourceSftpBulkUpdateExcelFormat: sourceSftpBulkUpdateExcelFormat,
			}
		}
		var globs []string = []string{}
		for _, globsItem := range streamsItem.Globs {
			globs = append(globs, globsItem.ValueString())
		}
		inputSchema := new(string)
		if !streamsItem.InputSchema.IsUnknown() && !streamsItem.InputSchema.IsNull() {
			*inputSchema = streamsItem.InputSchema.ValueString()
		} else {
			inputSchema = nil
		}
		var name2 string
		name2 = streamsItem.Name.ValueString()

		recentNFilesToReadForSchemaDiscovery := new(int64)
		if !streamsItem.RecentNFilesToReadForSchemaDiscovery.IsUnknown() && !streamsItem.RecentNFilesToReadForSchemaDiscovery.IsNull() {
			*recentNFilesToReadForSchemaDiscovery = streamsItem.RecentNFilesToReadForSchemaDiscovery.ValueInt64()
		} else {
			recentNFilesToReadForSchemaDiscovery = nil
		}
		schemaless := new(bool)
		if !streamsItem.Schemaless.IsUnknown() && !streamsItem.Schemaless.IsNull() {
			*schemaless = streamsItem.Schemaless.ValueBool()
		} else {
			schemaless = nil
		}
		validationPolicy := new(shared.SourceSftpBulkUpdateValidationPolicy)
		if !streamsItem.ValidationPolicy.IsUnknown() && !streamsItem.ValidationPolicy.IsNull() {
			*validationPolicy = shared.SourceSftpBulkUpdateValidationPolicy(streamsItem.ValidationPolicy.ValueString())
		} else {
			validationPolicy = nil
		}
		streams = append(streams, shared.SourceSftpBulkUpdateFileBasedStreamConfig{
			DaysToSyncIfHistoryIsFull:            daysToSyncIfHistoryIsFull,
			Format:                               format,
			Globs:                                globs,
			InputSchema:                          inputSchema,
			Name:                                 name2,
			RecentNFilesToReadForSchemaDiscovery: recentNFilesToReadForSchemaDiscovery,
			Schemaless:                           schemaless,
			ValidationPolicy:                     validationPolicy,
		})
	}
	var username string
	username = r.Configuration.Username.ValueString()

	configuration := shared.SourceSftpBulkUpdate{
		Credentials:    credentials,
		DeliveryMethod: deliveryMethod,
		FolderPath:     folderPath,
		Host:           host,
		Port:           port,
		StartDate:      startDate,
		Streams:        streams,
		Username:       username,
	}
	out := shared.SourceSftpBulkPutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
