// 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 *SourceGoogleDriveResourceModel) ToSharedSourceGoogleDriveCreateRequest() *shared.SourceGoogleDriveCreateRequest {
	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.SourceGoogleDriveAuthentication
	var sourceGoogleDriveAuthenticateViaGoogleOAuth *shared.SourceGoogleDriveAuthenticateViaGoogleOAuth
	if r.Configuration.Credentials.AuthenticateViaGoogleOAuth != nil {
		var clientID string
		clientID = r.Configuration.Credentials.AuthenticateViaGoogleOAuth.ClientID.ValueString()

		var clientSecret string
		clientSecret = r.Configuration.Credentials.AuthenticateViaGoogleOAuth.ClientSecret.ValueString()

		var refreshToken string
		refreshToken = r.Configuration.Credentials.AuthenticateViaGoogleOAuth.RefreshToken.ValueString()

		sourceGoogleDriveAuthenticateViaGoogleOAuth = &shared.SourceGoogleDriveAuthenticateViaGoogleOAuth{
			ClientID:     clientID,
			ClientSecret: clientSecret,
			RefreshToken: refreshToken,
		}
	}
	if sourceGoogleDriveAuthenticateViaGoogleOAuth != nil {
		credentials = shared.SourceGoogleDriveAuthentication{
			SourceGoogleDriveAuthenticateViaGoogleOAuth: sourceGoogleDriveAuthenticateViaGoogleOAuth,
		}
	}
	var sourceGoogleDriveServiceAccountKeyAuthentication *shared.SourceGoogleDriveServiceAccountKeyAuthentication
	if r.Configuration.Credentials.ServiceAccountKeyAuthentication != nil {
		var serviceAccountInfo string
		serviceAccountInfo = r.Configuration.Credentials.ServiceAccountKeyAuthentication.ServiceAccountInfo.ValueString()

		sourceGoogleDriveServiceAccountKeyAuthentication = &shared.SourceGoogleDriveServiceAccountKeyAuthentication{
			ServiceAccountInfo: serviceAccountInfo,
		}
	}
	if sourceGoogleDriveServiceAccountKeyAuthentication != nil {
		credentials = shared.SourceGoogleDriveAuthentication{
			SourceGoogleDriveServiceAccountKeyAuthentication: sourceGoogleDriveServiceAccountKeyAuthentication,
		}
	}
	var deliveryMethod *shared.DeliveryMethod
	if r.Configuration.DeliveryMethod != nil {
		var replicateRecords *shared.ReplicateRecords
		if r.Configuration.DeliveryMethod.ReplicateRecords != nil {
			replicateRecords = &shared.ReplicateRecords{}
		}
		if replicateRecords != nil {
			deliveryMethod = &shared.DeliveryMethod{
				ReplicateRecords: replicateRecords,
			}
		}
		var copyRawFiles *shared.CopyRawFiles
		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
			}
			copyRawFiles = &shared.CopyRawFiles{
				PreserveDirectoryStructure: preserveDirectoryStructure,
			}
		}
		if copyRawFiles != nil {
			deliveryMethod = &shared.DeliveryMethod{
				CopyRawFiles: copyRawFiles,
			}
		}
		var replicatePermissionsACL *shared.ReplicatePermissionsACL
		if r.Configuration.DeliveryMethod.ReplicatePermissionsACL != nil {
			domain := new(string)
			if !r.Configuration.DeliveryMethod.ReplicatePermissionsACL.Domain.IsUnknown() && !r.Configuration.DeliveryMethod.ReplicatePermissionsACL.Domain.IsNull() {
				*domain = r.Configuration.DeliveryMethod.ReplicatePermissionsACL.Domain.ValueString()
			} else {
				domain = nil
			}
			includeIdentitiesStream := new(bool)
			if !r.Configuration.DeliveryMethod.ReplicatePermissionsACL.IncludeIdentitiesStream.IsUnknown() && !r.Configuration.DeliveryMethod.ReplicatePermissionsACL.IncludeIdentitiesStream.IsNull() {
				*includeIdentitiesStream = r.Configuration.DeliveryMethod.ReplicatePermissionsACL.IncludeIdentitiesStream.ValueBool()
			} else {
				includeIdentitiesStream = nil
			}
			replicatePermissionsACL = &shared.ReplicatePermissionsACL{
				Domain:                  domain,
				IncludeIdentitiesStream: includeIdentitiesStream,
			}
		}
		if replicatePermissionsACL != nil {
			deliveryMethod = &shared.DeliveryMethod{
				ReplicatePermissionsACL: replicatePermissionsACL,
			}
		}
	}
	var folderURL string
	folderURL = r.Configuration.FolderURL.ValueString()

	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.SourceGoogleDriveFileBasedStreamConfig = []shared.SourceGoogleDriveFileBasedStreamConfig{}
	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.SourceGoogleDriveFormat
		var sourceGoogleDriveAvroFormat *shared.SourceGoogleDriveAvroFormat
		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
			}
			sourceGoogleDriveAvroFormat = &shared.SourceGoogleDriveAvroFormat{
				DoubleAsString: doubleAsString,
			}
		}
		if sourceGoogleDriveAvroFormat != nil {
			format = shared.SourceGoogleDriveFormat{
				SourceGoogleDriveAvroFormat: sourceGoogleDriveAvroFormat,
			}
		}
		var sourceGoogleDriveCSVFormat *shared.SourceGoogleDriveCSVFormat
		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.SourceGoogleDriveCSVHeaderDefinition
			if streamsItem.Format.CSVFormat.HeaderDefinition != nil {
				var sourceGoogleDriveFromCSV *shared.SourceGoogleDriveFromCSV
				if streamsItem.Format.CSVFormat.HeaderDefinition.FromCSV != nil {
					sourceGoogleDriveFromCSV = &shared.SourceGoogleDriveFromCSV{}
				}
				if sourceGoogleDriveFromCSV != nil {
					headerDefinition = &shared.SourceGoogleDriveCSVHeaderDefinition{
						SourceGoogleDriveFromCSV: sourceGoogleDriveFromCSV,
					}
				}
				var sourceGoogleDriveAutogenerated *shared.SourceGoogleDriveAutogenerated
				if streamsItem.Format.CSVFormat.HeaderDefinition.Autogenerated != nil {
					sourceGoogleDriveAutogenerated = &shared.SourceGoogleDriveAutogenerated{}
				}
				if sourceGoogleDriveAutogenerated != nil {
					headerDefinition = &shared.SourceGoogleDriveCSVHeaderDefinition{
						SourceGoogleDriveAutogenerated: sourceGoogleDriveAutogenerated,
					}
				}
				var sourceGoogleDriveUserProvided *shared.SourceGoogleDriveUserProvided
				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())
					}
					sourceGoogleDriveUserProvided = &shared.SourceGoogleDriveUserProvided{
						ColumnNames: columnNames,
					}
				}
				if sourceGoogleDriveUserProvided != nil {
					headerDefinition = &shared.SourceGoogleDriveCSVHeaderDefinition{
						SourceGoogleDriveUserProvided: sourceGoogleDriveUserProvided,
					}
				}
			}
			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())
			}
			sourceGoogleDriveCSVFormat = &shared.SourceGoogleDriveCSVFormat{
				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 sourceGoogleDriveCSVFormat != nil {
			format = shared.SourceGoogleDriveFormat{
				SourceGoogleDriveCSVFormat: sourceGoogleDriveCSVFormat,
			}
		}
		var sourceGoogleDriveJsonlFormat *shared.SourceGoogleDriveJsonlFormat
		if streamsItem.Format.JsonlFormat != nil {
			sourceGoogleDriveJsonlFormat = &shared.SourceGoogleDriveJsonlFormat{}
		}
		if sourceGoogleDriveJsonlFormat != nil {
			format = shared.SourceGoogleDriveFormat{
				SourceGoogleDriveJsonlFormat: sourceGoogleDriveJsonlFormat,
			}
		}
		var sourceGoogleDriveParquetFormat *shared.SourceGoogleDriveParquetFormat
		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
			}
			sourceGoogleDriveParquetFormat = &shared.SourceGoogleDriveParquetFormat{
				DecimalAsFloat: decimalAsFloat,
			}
		}
		if sourceGoogleDriveParquetFormat != nil {
			format = shared.SourceGoogleDriveFormat{
				SourceGoogleDriveParquetFormat: sourceGoogleDriveParquetFormat,
			}
		}
		var sourceGoogleDriveUnstructuredDocumentFormat *shared.SourceGoogleDriveUnstructuredDocumentFormat
		if streamsItem.Format.UnstructuredDocumentFormat != nil {
			var processing *shared.SourceGoogleDriveProcessing
			if streamsItem.Format.UnstructuredDocumentFormat.Processing != nil {
				var sourceGoogleDriveLocal *shared.SourceGoogleDriveLocal
				if streamsItem.Format.UnstructuredDocumentFormat.Processing.Local != nil {
					sourceGoogleDriveLocal = &shared.SourceGoogleDriveLocal{}
				}
				if sourceGoogleDriveLocal != nil {
					processing = &shared.SourceGoogleDriveProcessing{
						SourceGoogleDriveLocal: sourceGoogleDriveLocal,
					}
				}
			}
			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.SourceGoogleDriveParsingStrategy)
			if !streamsItem.Format.UnstructuredDocumentFormat.Strategy.IsUnknown() && !streamsItem.Format.UnstructuredDocumentFormat.Strategy.IsNull() {
				*strategy = shared.SourceGoogleDriveParsingStrategy(streamsItem.Format.UnstructuredDocumentFormat.Strategy.ValueString())
			} else {
				strategy = nil
			}
			sourceGoogleDriveUnstructuredDocumentFormat = &shared.SourceGoogleDriveUnstructuredDocumentFormat{
				Processing:             processing,
				SkipUnprocessableFiles: skipUnprocessableFiles,
				Strategy:               strategy,
			}
		}
		if sourceGoogleDriveUnstructuredDocumentFormat != nil {
			format = shared.SourceGoogleDriveFormat{
				SourceGoogleDriveUnstructuredDocumentFormat: sourceGoogleDriveUnstructuredDocumentFormat,
			}
		}
		var sourceGoogleDriveExcelFormat *shared.SourceGoogleDriveExcelFormat
		if streamsItem.Format.ExcelFormat != nil {
			sourceGoogleDriveExcelFormat = &shared.SourceGoogleDriveExcelFormat{}
		}
		if sourceGoogleDriveExcelFormat != nil {
			format = shared.SourceGoogleDriveFormat{
				SourceGoogleDriveExcelFormat: sourceGoogleDriveExcelFormat,
			}
		}
		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 name1 string
		name1 = 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.SourceGoogleDriveValidationPolicy)
		if !streamsItem.ValidationPolicy.IsUnknown() && !streamsItem.ValidationPolicy.IsNull() {
			*validationPolicy = shared.SourceGoogleDriveValidationPolicy(streamsItem.ValidationPolicy.ValueString())
		} else {
			validationPolicy = nil
		}
		streams = append(streams, shared.SourceGoogleDriveFileBasedStreamConfig{
			DaysToSyncIfHistoryIsFull:            daysToSyncIfHistoryIsFull,
			Format:                               format,
			Globs:                                globs,
			InputSchema:                          inputSchema,
			Name:                                 name1,
			RecentNFilesToReadForSchemaDiscovery: recentNFilesToReadForSchemaDiscovery,
			Schemaless:                           schemaless,
			ValidationPolicy:                     validationPolicy,
		})
	}
	configuration := shared.SourceGoogleDrive{
		Credentials:    credentials,
		DeliveryMethod: deliveryMethod,
		FolderURL:      folderURL,
		StartDate:      startDate,
		Streams:        streams,
	}
	secretID := new(string)
	if !r.SecretID.IsUnknown() && !r.SecretID.IsNull() {
		*secretID = r.SecretID.ValueString()
	} else {
		secretID = nil
	}
	out := shared.SourceGoogleDriveCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
		SecretID:      secretID,
	}
	return &out
}

func (r *SourceGoogleDriveResourceModel) 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 *SourceGoogleDriveResourceModel) ToSharedSourceGoogleDrivePutRequest() *shared.SourceGoogleDrivePutRequest {
	var name string
	name = r.Name.ValueString()

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

	var credentials shared.SourceGoogleDriveUpdateAuthentication
	var sourceGoogleDriveUpdateAuthenticateViaGoogleOAuth *shared.SourceGoogleDriveUpdateAuthenticateViaGoogleOAuth
	if r.Configuration.Credentials.AuthenticateViaGoogleOAuth != nil {
		var clientID string
		clientID = r.Configuration.Credentials.AuthenticateViaGoogleOAuth.ClientID.ValueString()

		var clientSecret string
		clientSecret = r.Configuration.Credentials.AuthenticateViaGoogleOAuth.ClientSecret.ValueString()

		var refreshToken string
		refreshToken = r.Configuration.Credentials.AuthenticateViaGoogleOAuth.RefreshToken.ValueString()

		sourceGoogleDriveUpdateAuthenticateViaGoogleOAuth = &shared.SourceGoogleDriveUpdateAuthenticateViaGoogleOAuth{
			ClientID:     clientID,
			ClientSecret: clientSecret,
			RefreshToken: refreshToken,
		}
	}
	if sourceGoogleDriveUpdateAuthenticateViaGoogleOAuth != nil {
		credentials = shared.SourceGoogleDriveUpdateAuthentication{
			SourceGoogleDriveUpdateAuthenticateViaGoogleOAuth: sourceGoogleDriveUpdateAuthenticateViaGoogleOAuth,
		}
	}
	var sourceGoogleDriveUpdateServiceAccountKeyAuthentication *shared.SourceGoogleDriveUpdateServiceAccountKeyAuthentication
	if r.Configuration.Credentials.ServiceAccountKeyAuthentication != nil {
		var serviceAccountInfo string
		serviceAccountInfo = r.Configuration.Credentials.ServiceAccountKeyAuthentication.ServiceAccountInfo.ValueString()

		sourceGoogleDriveUpdateServiceAccountKeyAuthentication = &shared.SourceGoogleDriveUpdateServiceAccountKeyAuthentication{
			ServiceAccountInfo: serviceAccountInfo,
		}
	}
	if sourceGoogleDriveUpdateServiceAccountKeyAuthentication != nil {
		credentials = shared.SourceGoogleDriveUpdateAuthentication{
			SourceGoogleDriveUpdateServiceAccountKeyAuthentication: sourceGoogleDriveUpdateServiceAccountKeyAuthentication,
		}
	}
	var deliveryMethod *shared.SourceGoogleDriveUpdateDeliveryMethod
	if r.Configuration.DeliveryMethod != nil {
		var sourceGoogleDriveUpdateReplicateRecords *shared.SourceGoogleDriveUpdateReplicateRecords
		if r.Configuration.DeliveryMethod.ReplicateRecords != nil {
			sourceGoogleDriveUpdateReplicateRecords = &shared.SourceGoogleDriveUpdateReplicateRecords{}
		}
		if sourceGoogleDriveUpdateReplicateRecords != nil {
			deliveryMethod = &shared.SourceGoogleDriveUpdateDeliveryMethod{
				SourceGoogleDriveUpdateReplicateRecords: sourceGoogleDriveUpdateReplicateRecords,
			}
		}
		var sourceGoogleDriveUpdateCopyRawFiles *shared.SourceGoogleDriveUpdateCopyRawFiles
		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
			}
			sourceGoogleDriveUpdateCopyRawFiles = &shared.SourceGoogleDriveUpdateCopyRawFiles{
				PreserveDirectoryStructure: preserveDirectoryStructure,
			}
		}
		if sourceGoogleDriveUpdateCopyRawFiles != nil {
			deliveryMethod = &shared.SourceGoogleDriveUpdateDeliveryMethod{
				SourceGoogleDriveUpdateCopyRawFiles: sourceGoogleDriveUpdateCopyRawFiles,
			}
		}
		var sourceGoogleDriveUpdateReplicatePermissionsACL *shared.SourceGoogleDriveUpdateReplicatePermissionsACL
		if r.Configuration.DeliveryMethod.ReplicatePermissionsACL != nil {
			domain := new(string)
			if !r.Configuration.DeliveryMethod.ReplicatePermissionsACL.Domain.IsUnknown() && !r.Configuration.DeliveryMethod.ReplicatePermissionsACL.Domain.IsNull() {
				*domain = r.Configuration.DeliveryMethod.ReplicatePermissionsACL.Domain.ValueString()
			} else {
				domain = nil
			}
			includeIdentitiesStream := new(bool)
			if !r.Configuration.DeliveryMethod.ReplicatePermissionsACL.IncludeIdentitiesStream.IsUnknown() && !r.Configuration.DeliveryMethod.ReplicatePermissionsACL.IncludeIdentitiesStream.IsNull() {
				*includeIdentitiesStream = r.Configuration.DeliveryMethod.ReplicatePermissionsACL.IncludeIdentitiesStream.ValueBool()
			} else {
				includeIdentitiesStream = nil
			}
			sourceGoogleDriveUpdateReplicatePermissionsACL = &shared.SourceGoogleDriveUpdateReplicatePermissionsACL{
				Domain:                  domain,
				IncludeIdentitiesStream: includeIdentitiesStream,
			}
		}
		if sourceGoogleDriveUpdateReplicatePermissionsACL != nil {
			deliveryMethod = &shared.SourceGoogleDriveUpdateDeliveryMethod{
				SourceGoogleDriveUpdateReplicatePermissionsACL: sourceGoogleDriveUpdateReplicatePermissionsACL,
			}
		}
	}
	var folderURL string
	folderURL = r.Configuration.FolderURL.ValueString()

	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.SourceGoogleDriveUpdateFileBasedStreamConfig = []shared.SourceGoogleDriveUpdateFileBasedStreamConfig{}
	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.SourceGoogleDriveUpdateFormat
		var sourceGoogleDriveUpdateAvroFormat *shared.SourceGoogleDriveUpdateAvroFormat
		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
			}
			sourceGoogleDriveUpdateAvroFormat = &shared.SourceGoogleDriveUpdateAvroFormat{
				DoubleAsString: doubleAsString,
			}
		}
		if sourceGoogleDriveUpdateAvroFormat != nil {
			format = shared.SourceGoogleDriveUpdateFormat{
				SourceGoogleDriveUpdateAvroFormat: sourceGoogleDriveUpdateAvroFormat,
			}
		}
		var sourceGoogleDriveUpdateCSVFormat *shared.SourceGoogleDriveUpdateCSVFormat
		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.SourceGoogleDriveUpdateCSVHeaderDefinition
			if streamsItem.Format.CSVFormat.HeaderDefinition != nil {
				var sourceGoogleDriveUpdateFromCSV *shared.SourceGoogleDriveUpdateFromCSV
				if streamsItem.Format.CSVFormat.HeaderDefinition.FromCSV != nil {
					sourceGoogleDriveUpdateFromCSV = &shared.SourceGoogleDriveUpdateFromCSV{}
				}
				if sourceGoogleDriveUpdateFromCSV != nil {
					headerDefinition = &shared.SourceGoogleDriveUpdateCSVHeaderDefinition{
						SourceGoogleDriveUpdateFromCSV: sourceGoogleDriveUpdateFromCSV,
					}
				}
				var sourceGoogleDriveUpdateAutogenerated *shared.SourceGoogleDriveUpdateAutogenerated
				if streamsItem.Format.CSVFormat.HeaderDefinition.Autogenerated != nil {
					sourceGoogleDriveUpdateAutogenerated = &shared.SourceGoogleDriveUpdateAutogenerated{}
				}
				if sourceGoogleDriveUpdateAutogenerated != nil {
					headerDefinition = &shared.SourceGoogleDriveUpdateCSVHeaderDefinition{
						SourceGoogleDriveUpdateAutogenerated: sourceGoogleDriveUpdateAutogenerated,
					}
				}
				var sourceGoogleDriveUpdateUserProvided *shared.SourceGoogleDriveUpdateUserProvided
				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())
					}
					sourceGoogleDriveUpdateUserProvided = &shared.SourceGoogleDriveUpdateUserProvided{
						ColumnNames: columnNames,
					}
				}
				if sourceGoogleDriveUpdateUserProvided != nil {
					headerDefinition = &shared.SourceGoogleDriveUpdateCSVHeaderDefinition{
						SourceGoogleDriveUpdateUserProvided: sourceGoogleDriveUpdateUserProvided,
					}
				}
			}
			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())
			}
			sourceGoogleDriveUpdateCSVFormat = &shared.SourceGoogleDriveUpdateCSVFormat{
				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 sourceGoogleDriveUpdateCSVFormat != nil {
			format = shared.SourceGoogleDriveUpdateFormat{
				SourceGoogleDriveUpdateCSVFormat: sourceGoogleDriveUpdateCSVFormat,
			}
		}
		var sourceGoogleDriveUpdateJsonlFormat *shared.SourceGoogleDriveUpdateJsonlFormat
		if streamsItem.Format.JsonlFormat != nil {
			sourceGoogleDriveUpdateJsonlFormat = &shared.SourceGoogleDriveUpdateJsonlFormat{}
		}
		if sourceGoogleDriveUpdateJsonlFormat != nil {
			format = shared.SourceGoogleDriveUpdateFormat{
				SourceGoogleDriveUpdateJsonlFormat: sourceGoogleDriveUpdateJsonlFormat,
			}
		}
		var sourceGoogleDriveUpdateParquetFormat *shared.SourceGoogleDriveUpdateParquetFormat
		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
			}
			sourceGoogleDriveUpdateParquetFormat = &shared.SourceGoogleDriveUpdateParquetFormat{
				DecimalAsFloat: decimalAsFloat,
			}
		}
		if sourceGoogleDriveUpdateParquetFormat != nil {
			format = shared.SourceGoogleDriveUpdateFormat{
				SourceGoogleDriveUpdateParquetFormat: sourceGoogleDriveUpdateParquetFormat,
			}
		}
		var sourceGoogleDriveUpdateUnstructuredDocumentFormat *shared.SourceGoogleDriveUpdateUnstructuredDocumentFormat
		if streamsItem.Format.UnstructuredDocumentFormat != nil {
			var processing *shared.SourceGoogleDriveUpdateProcessing
			if streamsItem.Format.UnstructuredDocumentFormat.Processing != nil {
				var sourceGoogleDriveUpdateLocal *shared.SourceGoogleDriveUpdateLocal
				if streamsItem.Format.UnstructuredDocumentFormat.Processing.Local != nil {
					sourceGoogleDriveUpdateLocal = &shared.SourceGoogleDriveUpdateLocal{}
				}
				if sourceGoogleDriveUpdateLocal != nil {
					processing = &shared.SourceGoogleDriveUpdateProcessing{
						SourceGoogleDriveUpdateLocal: sourceGoogleDriveUpdateLocal,
					}
				}
			}
			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.SourceGoogleDriveUpdateParsingStrategy)
			if !streamsItem.Format.UnstructuredDocumentFormat.Strategy.IsUnknown() && !streamsItem.Format.UnstructuredDocumentFormat.Strategy.IsNull() {
				*strategy = shared.SourceGoogleDriveUpdateParsingStrategy(streamsItem.Format.UnstructuredDocumentFormat.Strategy.ValueString())
			} else {
				strategy = nil
			}
			sourceGoogleDriveUpdateUnstructuredDocumentFormat = &shared.SourceGoogleDriveUpdateUnstructuredDocumentFormat{
				Processing:             processing,
				SkipUnprocessableFiles: skipUnprocessableFiles,
				Strategy:               strategy,
			}
		}
		if sourceGoogleDriveUpdateUnstructuredDocumentFormat != nil {
			format = shared.SourceGoogleDriveUpdateFormat{
				SourceGoogleDriveUpdateUnstructuredDocumentFormat: sourceGoogleDriveUpdateUnstructuredDocumentFormat,
			}
		}
		var sourceGoogleDriveUpdateExcelFormat *shared.SourceGoogleDriveUpdateExcelFormat
		if streamsItem.Format.ExcelFormat != nil {
			sourceGoogleDriveUpdateExcelFormat = &shared.SourceGoogleDriveUpdateExcelFormat{}
		}
		if sourceGoogleDriveUpdateExcelFormat != nil {
			format = shared.SourceGoogleDriveUpdateFormat{
				SourceGoogleDriveUpdateExcelFormat: sourceGoogleDriveUpdateExcelFormat,
			}
		}
		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 name1 string
		name1 = 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.SourceGoogleDriveUpdateValidationPolicy)
		if !streamsItem.ValidationPolicy.IsUnknown() && !streamsItem.ValidationPolicy.IsNull() {
			*validationPolicy = shared.SourceGoogleDriveUpdateValidationPolicy(streamsItem.ValidationPolicy.ValueString())
		} else {
			validationPolicy = nil
		}
		streams = append(streams, shared.SourceGoogleDriveUpdateFileBasedStreamConfig{
			DaysToSyncIfHistoryIsFull:            daysToSyncIfHistoryIsFull,
			Format:                               format,
			Globs:                                globs,
			InputSchema:                          inputSchema,
			Name:                                 name1,
			RecentNFilesToReadForSchemaDiscovery: recentNFilesToReadForSchemaDiscovery,
			Schemaless:                           schemaless,
			ValidationPolicy:                     validationPolicy,
		})
	}
	configuration := shared.SourceGoogleDriveUpdate{
		Credentials:    credentials,
		DeliveryMethod: deliveryMethod,
		FolderURL:      folderURL,
		StartDate:      startDate,
		Streams:        streams,
	}
	out := shared.SourceGoogleDrivePutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
