// 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 *DestinationFireboltResourceModel) ToSharedDestinationFireboltCreateRequest() *shared.DestinationFireboltCreateRequest {
	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 account string
	account = r.Configuration.Account.ValueString()

	var clientID string
	clientID = r.Configuration.ClientID.ValueString()

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

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

	var engine string
	engine = r.Configuration.Engine.ValueString()

	host := new(string)
	if !r.Configuration.Host.IsUnknown() && !r.Configuration.Host.IsNull() {
		*host = r.Configuration.Host.ValueString()
	} else {
		host = nil
	}
	var loadingMethod *shared.DestinationFireboltLoadingMethod
	if r.Configuration.LoadingMethod != nil {
		var sqlInserts *shared.SQLInserts
		if r.Configuration.LoadingMethod.SQLInserts != nil {
			sqlInserts = &shared.SQLInserts{}
		}
		if sqlInserts != nil {
			loadingMethod = &shared.DestinationFireboltLoadingMethod{
				SQLInserts: sqlInserts,
			}
		}
		var externalTableViaS3 *shared.ExternalTableViaS3
		if r.Configuration.LoadingMethod.ExternalTableViaS3 != nil {
			var awsKeyID string
			awsKeyID = r.Configuration.LoadingMethod.ExternalTableViaS3.AwsKeyID.ValueString()

			var awsKeySecret string
			awsKeySecret = r.Configuration.LoadingMethod.ExternalTableViaS3.AwsKeySecret.ValueString()

			var s3Bucket string
			s3Bucket = r.Configuration.LoadingMethod.ExternalTableViaS3.S3Bucket.ValueString()

			var s3Region string
			s3Region = r.Configuration.LoadingMethod.ExternalTableViaS3.S3Region.ValueString()

			externalTableViaS3 = &shared.ExternalTableViaS3{
				AwsKeyID:     awsKeyID,
				AwsKeySecret: awsKeySecret,
				S3Bucket:     s3Bucket,
				S3Region:     s3Region,
			}
		}
		if externalTableViaS3 != nil {
			loadingMethod = &shared.DestinationFireboltLoadingMethod{
				ExternalTableViaS3: externalTableViaS3,
			}
		}
	}
	configuration := shared.DestinationFirebolt{
		Account:       account,
		ClientID:      clientID,
		ClientSecret:  clientSecret,
		Database:      database,
		Engine:        engine,
		Host:          host,
		LoadingMethod: loadingMethod,
	}
	out := shared.DestinationFireboltCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}

func (r *DestinationFireboltResourceModel) 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 *DestinationFireboltResourceModel) ToSharedDestinationFireboltPutRequest() *shared.DestinationFireboltPutRequest {
	var name string
	name = r.Name.ValueString()

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

	var account string
	account = r.Configuration.Account.ValueString()

	var clientID string
	clientID = r.Configuration.ClientID.ValueString()

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

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

	var engine string
	engine = r.Configuration.Engine.ValueString()

	host := new(string)
	if !r.Configuration.Host.IsUnknown() && !r.Configuration.Host.IsNull() {
		*host = r.Configuration.Host.ValueString()
	} else {
		host = nil
	}
	var loadingMethod *shared.DestinationFireboltUpdateLoadingMethod
	if r.Configuration.LoadingMethod != nil {
		var destinationFireboltUpdateSQLInserts *shared.DestinationFireboltUpdateSQLInserts
		if r.Configuration.LoadingMethod.SQLInserts != nil {
			destinationFireboltUpdateSQLInserts = &shared.DestinationFireboltUpdateSQLInserts{}
		}
		if destinationFireboltUpdateSQLInserts != nil {
			loadingMethod = &shared.DestinationFireboltUpdateLoadingMethod{
				DestinationFireboltUpdateSQLInserts: destinationFireboltUpdateSQLInserts,
			}
		}
		var destinationFireboltUpdateExternalTableViaS3 *shared.DestinationFireboltUpdateExternalTableViaS3
		if r.Configuration.LoadingMethod.ExternalTableViaS3 != nil {
			var awsKeyID string
			awsKeyID = r.Configuration.LoadingMethod.ExternalTableViaS3.AwsKeyID.ValueString()

			var awsKeySecret string
			awsKeySecret = r.Configuration.LoadingMethod.ExternalTableViaS3.AwsKeySecret.ValueString()

			var s3Bucket string
			s3Bucket = r.Configuration.LoadingMethod.ExternalTableViaS3.S3Bucket.ValueString()

			var s3Region string
			s3Region = r.Configuration.LoadingMethod.ExternalTableViaS3.S3Region.ValueString()

			destinationFireboltUpdateExternalTableViaS3 = &shared.DestinationFireboltUpdateExternalTableViaS3{
				AwsKeyID:     awsKeyID,
				AwsKeySecret: awsKeySecret,
				S3Bucket:     s3Bucket,
				S3Region:     s3Region,
			}
		}
		if destinationFireboltUpdateExternalTableViaS3 != nil {
			loadingMethod = &shared.DestinationFireboltUpdateLoadingMethod{
				DestinationFireboltUpdateExternalTableViaS3: destinationFireboltUpdateExternalTableViaS3,
			}
		}
	}
	configuration := shared.DestinationFireboltUpdate{
		Account:       account,
		ClientID:      clientID,
		ClientSecret:  clientSecret,
		Database:      database,
		Engine:        engine,
		Host:          host,
		LoadingMethod: loadingMethod,
	}
	out := shared.DestinationFireboltPutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
