// 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 *DestinationAwsDatalakeResourceModel) ToSharedDestinationAwsDatalakeCreateRequest() *shared.DestinationAwsDatalakeCreateRequest {
	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()

	awsAccountID := new(string)
	if !r.Configuration.AwsAccountID.IsUnknown() && !r.Configuration.AwsAccountID.IsNull() {
		*awsAccountID = r.Configuration.AwsAccountID.ValueString()
	} else {
		awsAccountID = nil
	}
	var bucketName string
	bucketName = r.Configuration.BucketName.ValueString()

	bucketPrefix := new(string)
	if !r.Configuration.BucketPrefix.IsUnknown() && !r.Configuration.BucketPrefix.IsNull() {
		*bucketPrefix = r.Configuration.BucketPrefix.ValueString()
	} else {
		bucketPrefix = nil
	}
	var credentials shared.AuthenticationMode
	var iamRole *shared.IAMRole
	if r.Configuration.Credentials.IAMRole != nil {
		var roleArn string
		roleArn = r.Configuration.Credentials.IAMRole.RoleArn.ValueString()

		iamRole = &shared.IAMRole{
			RoleArn: roleArn,
		}
	}
	if iamRole != nil {
		credentials = shared.AuthenticationMode{
			IAMRole: iamRole,
		}
	}
	var iamUser *shared.IAMUser
	if r.Configuration.Credentials.IAMUser != nil {
		var awsAccessKeyID string
		awsAccessKeyID = r.Configuration.Credentials.IAMUser.AwsAccessKeyID.ValueString()

		var awsSecretAccessKey string
		awsSecretAccessKey = r.Configuration.Credentials.IAMUser.AwsSecretAccessKey.ValueString()

		iamUser = &shared.IAMUser{
			AwsAccessKeyID:     awsAccessKeyID,
			AwsSecretAccessKey: awsSecretAccessKey,
		}
	}
	if iamUser != nil {
		credentials = shared.AuthenticationMode{
			IAMUser: iamUser,
		}
	}
	var format *shared.OutputFormatWildcard
	if r.Configuration.Format != nil {
		var jsonLinesNewlineDelimitedJSON *shared.JSONLinesNewlineDelimitedJSON
		if r.Configuration.Format.JSONLinesNewlineDelimitedJSON != nil {
			compressionCodec := new(shared.CompressionCodecOptional)
			if !r.Configuration.Format.JSONLinesNewlineDelimitedJSON.CompressionCodec.IsUnknown() && !r.Configuration.Format.JSONLinesNewlineDelimitedJSON.CompressionCodec.IsNull() {
				*compressionCodec = shared.CompressionCodecOptional(r.Configuration.Format.JSONLinesNewlineDelimitedJSON.CompressionCodec.ValueString())
			} else {
				compressionCodec = nil
			}
			formatType := new(shared.FormatTypeWildcard)
			if !r.Configuration.Format.JSONLinesNewlineDelimitedJSON.FormatType.IsUnknown() && !r.Configuration.Format.JSONLinesNewlineDelimitedJSON.FormatType.IsNull() {
				*formatType = shared.FormatTypeWildcard(r.Configuration.Format.JSONLinesNewlineDelimitedJSON.FormatType.ValueString())
			} else {
				formatType = nil
			}
			jsonLinesNewlineDelimitedJSON = &shared.JSONLinesNewlineDelimitedJSON{
				CompressionCodec: compressionCodec,
				FormatType:       formatType,
			}
		}
		if jsonLinesNewlineDelimitedJSON != nil {
			format = &shared.OutputFormatWildcard{
				JSONLinesNewlineDelimitedJSON: jsonLinesNewlineDelimitedJSON,
			}
		}
		var parquetColumnarStorage *shared.ParquetColumnarStorage
		if r.Configuration.Format.ParquetColumnarStorage != nil {
			compressionCodec1 := new(shared.DestinationAwsDatalakeCompressionCodecOptional)
			if !r.Configuration.Format.ParquetColumnarStorage.CompressionCodec.IsUnknown() && !r.Configuration.Format.ParquetColumnarStorage.CompressionCodec.IsNull() {
				*compressionCodec1 = shared.DestinationAwsDatalakeCompressionCodecOptional(r.Configuration.Format.ParquetColumnarStorage.CompressionCodec.ValueString())
			} else {
				compressionCodec1 = nil
			}
			formatType1 := new(shared.DestinationAwsDatalakeFormatTypeWildcard)
			if !r.Configuration.Format.ParquetColumnarStorage.FormatType.IsUnknown() && !r.Configuration.Format.ParquetColumnarStorage.FormatType.IsNull() {
				*formatType1 = shared.DestinationAwsDatalakeFormatTypeWildcard(r.Configuration.Format.ParquetColumnarStorage.FormatType.ValueString())
			} else {
				formatType1 = nil
			}
			parquetColumnarStorage = &shared.ParquetColumnarStorage{
				CompressionCodec: compressionCodec1,
				FormatType:       formatType1,
			}
		}
		if parquetColumnarStorage != nil {
			format = &shared.OutputFormatWildcard{
				ParquetColumnarStorage: parquetColumnarStorage,
			}
		}
	}
	glueCatalogFloatAsDecimal := new(bool)
	if !r.Configuration.GlueCatalogFloatAsDecimal.IsUnknown() && !r.Configuration.GlueCatalogFloatAsDecimal.IsNull() {
		*glueCatalogFloatAsDecimal = r.Configuration.GlueCatalogFloatAsDecimal.ValueBool()
	} else {
		glueCatalogFloatAsDecimal = nil
	}
	lakeformationDatabaseDefaultTagKey := new(string)
	if !r.Configuration.LakeformationDatabaseDefaultTagKey.IsUnknown() && !r.Configuration.LakeformationDatabaseDefaultTagKey.IsNull() {
		*lakeformationDatabaseDefaultTagKey = r.Configuration.LakeformationDatabaseDefaultTagKey.ValueString()
	} else {
		lakeformationDatabaseDefaultTagKey = nil
	}
	lakeformationDatabaseDefaultTagValues := new(string)
	if !r.Configuration.LakeformationDatabaseDefaultTagValues.IsUnknown() && !r.Configuration.LakeformationDatabaseDefaultTagValues.IsNull() {
		*lakeformationDatabaseDefaultTagValues = r.Configuration.LakeformationDatabaseDefaultTagValues.ValueString()
	} else {
		lakeformationDatabaseDefaultTagValues = nil
	}
	var lakeformationDatabaseName string
	lakeformationDatabaseName = r.Configuration.LakeformationDatabaseName.ValueString()

	lakeformationGovernedTables := new(bool)
	if !r.Configuration.LakeformationGovernedTables.IsUnknown() && !r.Configuration.LakeformationGovernedTables.IsNull() {
		*lakeformationGovernedTables = r.Configuration.LakeformationGovernedTables.ValueBool()
	} else {
		lakeformationGovernedTables = nil
	}
	partitioning := new(shared.ChooseHowToPartitionData)
	if !r.Configuration.Partitioning.IsUnknown() && !r.Configuration.Partitioning.IsNull() {
		*partitioning = shared.ChooseHowToPartitionData(r.Configuration.Partitioning.ValueString())
	} else {
		partitioning = nil
	}
	region := new(shared.S3BucketRegion)
	if !r.Configuration.Region.IsUnknown() && !r.Configuration.Region.IsNull() {
		*region = shared.S3BucketRegion(r.Configuration.Region.ValueString())
	} else {
		region = nil
	}
	configuration := shared.DestinationAwsDatalake{
		AwsAccountID:                          awsAccountID,
		BucketName:                            bucketName,
		BucketPrefix:                          bucketPrefix,
		Credentials:                           credentials,
		Format:                                format,
		GlueCatalogFloatAsDecimal:             glueCatalogFloatAsDecimal,
		LakeformationDatabaseDefaultTagKey:    lakeformationDatabaseDefaultTagKey,
		LakeformationDatabaseDefaultTagValues: lakeformationDatabaseDefaultTagValues,
		LakeformationDatabaseName:             lakeformationDatabaseName,
		LakeformationGovernedTables:           lakeformationGovernedTables,
		Partitioning:                          partitioning,
		Region:                                region,
	}
	out := shared.DestinationAwsDatalakeCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}

func (r *DestinationAwsDatalakeResourceModel) 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 *DestinationAwsDatalakeResourceModel) ToSharedDestinationAwsDatalakePutRequest() *shared.DestinationAwsDatalakePutRequest {
	var name string
	name = r.Name.ValueString()

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

	awsAccountID := new(string)
	if !r.Configuration.AwsAccountID.IsUnknown() && !r.Configuration.AwsAccountID.IsNull() {
		*awsAccountID = r.Configuration.AwsAccountID.ValueString()
	} else {
		awsAccountID = nil
	}
	var bucketName string
	bucketName = r.Configuration.BucketName.ValueString()

	bucketPrefix := new(string)
	if !r.Configuration.BucketPrefix.IsUnknown() && !r.Configuration.BucketPrefix.IsNull() {
		*bucketPrefix = r.Configuration.BucketPrefix.ValueString()
	} else {
		bucketPrefix = nil
	}
	var credentials shared.DestinationAwsDatalakeUpdateAuthenticationMode
	var destinationAwsDatalakeUpdateIAMRole *shared.DestinationAwsDatalakeUpdateIAMRole
	if r.Configuration.Credentials.IAMRole != nil {
		var roleArn string
		roleArn = r.Configuration.Credentials.IAMRole.RoleArn.ValueString()

		destinationAwsDatalakeUpdateIAMRole = &shared.DestinationAwsDatalakeUpdateIAMRole{
			RoleArn: roleArn,
		}
	}
	if destinationAwsDatalakeUpdateIAMRole != nil {
		credentials = shared.DestinationAwsDatalakeUpdateAuthenticationMode{
			DestinationAwsDatalakeUpdateIAMRole: destinationAwsDatalakeUpdateIAMRole,
		}
	}
	var destinationAwsDatalakeUpdateIAMUser *shared.DestinationAwsDatalakeUpdateIAMUser
	if r.Configuration.Credentials.IAMUser != nil {
		var awsAccessKeyID string
		awsAccessKeyID = r.Configuration.Credentials.IAMUser.AwsAccessKeyID.ValueString()

		var awsSecretAccessKey string
		awsSecretAccessKey = r.Configuration.Credentials.IAMUser.AwsSecretAccessKey.ValueString()

		destinationAwsDatalakeUpdateIAMUser = &shared.DestinationAwsDatalakeUpdateIAMUser{
			AwsAccessKeyID:     awsAccessKeyID,
			AwsSecretAccessKey: awsSecretAccessKey,
		}
	}
	if destinationAwsDatalakeUpdateIAMUser != nil {
		credentials = shared.DestinationAwsDatalakeUpdateAuthenticationMode{
			DestinationAwsDatalakeUpdateIAMUser: destinationAwsDatalakeUpdateIAMUser,
		}
	}
	var format *shared.DestinationAwsDatalakeUpdateOutputFormatWildcard
	if r.Configuration.Format != nil {
		var destinationAwsDatalakeUpdateJSONLinesNewlineDelimitedJSON *shared.DestinationAwsDatalakeUpdateJSONLinesNewlineDelimitedJSON
		if r.Configuration.Format.JSONLinesNewlineDelimitedJSON != nil {
			compressionCodec := new(shared.DestinationAwsDatalakeUpdateCompressionCodecOptional)
			if !r.Configuration.Format.JSONLinesNewlineDelimitedJSON.CompressionCodec.IsUnknown() && !r.Configuration.Format.JSONLinesNewlineDelimitedJSON.CompressionCodec.IsNull() {
				*compressionCodec = shared.DestinationAwsDatalakeUpdateCompressionCodecOptional(r.Configuration.Format.JSONLinesNewlineDelimitedJSON.CompressionCodec.ValueString())
			} else {
				compressionCodec = nil
			}
			formatType := new(shared.DestinationAwsDatalakeUpdateFormatTypeWildcard)
			if !r.Configuration.Format.JSONLinesNewlineDelimitedJSON.FormatType.IsUnknown() && !r.Configuration.Format.JSONLinesNewlineDelimitedJSON.FormatType.IsNull() {
				*formatType = shared.DestinationAwsDatalakeUpdateFormatTypeWildcard(r.Configuration.Format.JSONLinesNewlineDelimitedJSON.FormatType.ValueString())
			} else {
				formatType = nil
			}
			destinationAwsDatalakeUpdateJSONLinesNewlineDelimitedJSON = &shared.DestinationAwsDatalakeUpdateJSONLinesNewlineDelimitedJSON{
				CompressionCodec: compressionCodec,
				FormatType:       formatType,
			}
		}
		if destinationAwsDatalakeUpdateJSONLinesNewlineDelimitedJSON != nil {
			format = &shared.DestinationAwsDatalakeUpdateOutputFormatWildcard{
				DestinationAwsDatalakeUpdateJSONLinesNewlineDelimitedJSON: destinationAwsDatalakeUpdateJSONLinesNewlineDelimitedJSON,
			}
		}
		var destinationAwsDatalakeUpdateParquetColumnarStorage *shared.DestinationAwsDatalakeUpdateParquetColumnarStorage
		if r.Configuration.Format.ParquetColumnarStorage != nil {
			compressionCodec1 := new(shared.DestinationAwsDatalakeUpdateSchemasCompressionCodecOptional)
			if !r.Configuration.Format.ParquetColumnarStorage.CompressionCodec.IsUnknown() && !r.Configuration.Format.ParquetColumnarStorage.CompressionCodec.IsNull() {
				*compressionCodec1 = shared.DestinationAwsDatalakeUpdateSchemasCompressionCodecOptional(r.Configuration.Format.ParquetColumnarStorage.CompressionCodec.ValueString())
			} else {
				compressionCodec1 = nil
			}
			formatType1 := new(shared.DestinationAwsDatalakeUpdateSchemasFormatTypeWildcard)
			if !r.Configuration.Format.ParquetColumnarStorage.FormatType.IsUnknown() && !r.Configuration.Format.ParquetColumnarStorage.FormatType.IsNull() {
				*formatType1 = shared.DestinationAwsDatalakeUpdateSchemasFormatTypeWildcard(r.Configuration.Format.ParquetColumnarStorage.FormatType.ValueString())
			} else {
				formatType1 = nil
			}
			destinationAwsDatalakeUpdateParquetColumnarStorage = &shared.DestinationAwsDatalakeUpdateParquetColumnarStorage{
				CompressionCodec: compressionCodec1,
				FormatType:       formatType1,
			}
		}
		if destinationAwsDatalakeUpdateParquetColumnarStorage != nil {
			format = &shared.DestinationAwsDatalakeUpdateOutputFormatWildcard{
				DestinationAwsDatalakeUpdateParquetColumnarStorage: destinationAwsDatalakeUpdateParquetColumnarStorage,
			}
		}
	}
	glueCatalogFloatAsDecimal := new(bool)
	if !r.Configuration.GlueCatalogFloatAsDecimal.IsUnknown() && !r.Configuration.GlueCatalogFloatAsDecimal.IsNull() {
		*glueCatalogFloatAsDecimal = r.Configuration.GlueCatalogFloatAsDecimal.ValueBool()
	} else {
		glueCatalogFloatAsDecimal = nil
	}
	lakeformationDatabaseDefaultTagKey := new(string)
	if !r.Configuration.LakeformationDatabaseDefaultTagKey.IsUnknown() && !r.Configuration.LakeformationDatabaseDefaultTagKey.IsNull() {
		*lakeformationDatabaseDefaultTagKey = r.Configuration.LakeformationDatabaseDefaultTagKey.ValueString()
	} else {
		lakeformationDatabaseDefaultTagKey = nil
	}
	lakeformationDatabaseDefaultTagValues := new(string)
	if !r.Configuration.LakeformationDatabaseDefaultTagValues.IsUnknown() && !r.Configuration.LakeformationDatabaseDefaultTagValues.IsNull() {
		*lakeformationDatabaseDefaultTagValues = r.Configuration.LakeformationDatabaseDefaultTagValues.ValueString()
	} else {
		lakeformationDatabaseDefaultTagValues = nil
	}
	var lakeformationDatabaseName string
	lakeformationDatabaseName = r.Configuration.LakeformationDatabaseName.ValueString()

	lakeformationGovernedTables := new(bool)
	if !r.Configuration.LakeformationGovernedTables.IsUnknown() && !r.Configuration.LakeformationGovernedTables.IsNull() {
		*lakeformationGovernedTables = r.Configuration.LakeformationGovernedTables.ValueBool()
	} else {
		lakeformationGovernedTables = nil
	}
	partitioning := new(shared.DestinationAwsDatalakeUpdateChooseHowToPartitionData)
	if !r.Configuration.Partitioning.IsUnknown() && !r.Configuration.Partitioning.IsNull() {
		*partitioning = shared.DestinationAwsDatalakeUpdateChooseHowToPartitionData(r.Configuration.Partitioning.ValueString())
	} else {
		partitioning = nil
	}
	region := new(shared.DestinationAwsDatalakeUpdateS3BucketRegion)
	if !r.Configuration.Region.IsUnknown() && !r.Configuration.Region.IsNull() {
		*region = shared.DestinationAwsDatalakeUpdateS3BucketRegion(r.Configuration.Region.ValueString())
	} else {
		region = nil
	}
	configuration := shared.DestinationAwsDatalakeUpdate{
		AwsAccountID:                          awsAccountID,
		BucketName:                            bucketName,
		BucketPrefix:                          bucketPrefix,
		Credentials:                           credentials,
		Format:                                format,
		GlueCatalogFloatAsDecimal:             glueCatalogFloatAsDecimal,
		LakeformationDatabaseDefaultTagKey:    lakeformationDatabaseDefaultTagKey,
		LakeformationDatabaseDefaultTagValues: lakeformationDatabaseDefaultTagValues,
		LakeformationDatabaseName:             lakeformationDatabaseName,
		LakeformationGovernedTables:           lakeformationGovernedTables,
		Partitioning:                          partitioning,
		Region:                                region,
	}
	out := shared.DestinationAwsDatalakePutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
