// 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 *SourceRentcastResourceModel) ToSharedSourceRentcastCreateRequest() *shared.SourceRentcastCreateRequest {
	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()

	address := new(string)
	if !r.Configuration.Address.IsUnknown() && !r.Configuration.Address.IsNull() {
		*address = r.Configuration.Address.ValueString()
	} else {
		address = nil
	}
	var apiKey string
	apiKey = r.Configuration.APIKey.ValueString()

	bathRooms := new(int64)
	if !r.Configuration.BathRooms.IsUnknown() && !r.Configuration.BathRooms.IsNull() {
		*bathRooms = r.Configuration.BathRooms.ValueInt64()
	} else {
		bathRooms = nil
	}
	bedrooms := new(float64)
	if !r.Configuration.Bedrooms.IsUnknown() && !r.Configuration.Bedrooms.IsNull() {
		*bedrooms, _ = r.Configuration.Bedrooms.ValueBigFloat().Float64()
	} else {
		bedrooms = nil
	}
	city := new(string)
	if !r.Configuration.City.IsUnknown() && !r.Configuration.City.IsNull() {
		*city = r.Configuration.City.ValueString()
	} else {
		city = nil
	}
	dataType := new(string)
	if !r.Configuration.DataType.IsUnknown() && !r.Configuration.DataType.IsNull() {
		*dataType = r.Configuration.DataType.ValueString()
	} else {
		dataType = nil
	}
	daysOld := new(string)
	if !r.Configuration.DaysOld.IsUnknown() && !r.Configuration.DaysOld.IsNull() {
		*daysOld = r.Configuration.DaysOld.ValueString()
	} else {
		daysOld = nil
	}
	historyRange := new(string)
	if !r.Configuration.HistoryRange.IsUnknown() && !r.Configuration.HistoryRange.IsNull() {
		*historyRange = r.Configuration.HistoryRange.ValueString()
	} else {
		historyRange = nil
	}
	latitude := new(string)
	if !r.Configuration.Latitude.IsUnknown() && !r.Configuration.Latitude.IsNull() {
		*latitude = r.Configuration.Latitude.ValueString()
	} else {
		latitude = nil
	}
	longitude := new(string)
	if !r.Configuration.Longitude.IsUnknown() && !r.Configuration.Longitude.IsNull() {
		*longitude = r.Configuration.Longitude.ValueString()
	} else {
		longitude = nil
	}
	propertyType := new(string)
	if !r.Configuration.PropertyType.IsUnknown() && !r.Configuration.PropertyType.IsNull() {
		*propertyType = r.Configuration.PropertyType.ValueString()
	} else {
		propertyType = nil
	}
	radius := new(string)
	if !r.Configuration.Radius.IsUnknown() && !r.Configuration.Radius.IsNull() {
		*radius = r.Configuration.Radius.ValueString()
	} else {
		radius = nil
	}
	state := new(string)
	if !r.Configuration.State.IsUnknown() && !r.Configuration.State.IsNull() {
		*state = r.Configuration.State.ValueString()
	} else {
		state = nil
	}
	status := new(string)
	if !r.Configuration.Status.IsUnknown() && !r.Configuration.Status.IsNull() {
		*status = r.Configuration.Status.ValueString()
	} else {
		status = nil
	}
	zipcode := new(string)
	if !r.Configuration.Zipcode.IsUnknown() && !r.Configuration.Zipcode.IsNull() {
		*zipcode = r.Configuration.Zipcode.ValueString()
	} else {
		zipcode = nil
	}
	configuration := shared.SourceRentcast{
		Address:      address,
		APIKey:       apiKey,
		BathRooms:    bathRooms,
		Bedrooms:     bedrooms,
		City:         city,
		DataType:     dataType,
		DaysOld:      daysOld,
		HistoryRange: historyRange,
		Latitude:     latitude,
		Longitude:    longitude,
		PropertyType: propertyType,
		Radius:       radius,
		State:        state,
		Status:       status,
		Zipcode:      zipcode,
	}
	secretID := new(string)
	if !r.SecretID.IsUnknown() && !r.SecretID.IsNull() {
		*secretID = r.SecretID.ValueString()
	} else {
		secretID = nil
	}
	out := shared.SourceRentcastCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
		SecretID:      secretID,
	}
	return &out
}

func (r *SourceRentcastResourceModel) 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 *SourceRentcastResourceModel) ToSharedSourceRentcastPutRequest() *shared.SourceRentcastPutRequest {
	var name string
	name = r.Name.ValueString()

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

	address := new(string)
	if !r.Configuration.Address.IsUnknown() && !r.Configuration.Address.IsNull() {
		*address = r.Configuration.Address.ValueString()
	} else {
		address = nil
	}
	var apiKey string
	apiKey = r.Configuration.APIKey.ValueString()

	bathRooms := new(int64)
	if !r.Configuration.BathRooms.IsUnknown() && !r.Configuration.BathRooms.IsNull() {
		*bathRooms = r.Configuration.BathRooms.ValueInt64()
	} else {
		bathRooms = nil
	}
	bedrooms := new(float64)
	if !r.Configuration.Bedrooms.IsUnknown() && !r.Configuration.Bedrooms.IsNull() {
		*bedrooms, _ = r.Configuration.Bedrooms.ValueBigFloat().Float64()
	} else {
		bedrooms = nil
	}
	city := new(string)
	if !r.Configuration.City.IsUnknown() && !r.Configuration.City.IsNull() {
		*city = r.Configuration.City.ValueString()
	} else {
		city = nil
	}
	dataType := new(string)
	if !r.Configuration.DataType.IsUnknown() && !r.Configuration.DataType.IsNull() {
		*dataType = r.Configuration.DataType.ValueString()
	} else {
		dataType = nil
	}
	daysOld := new(string)
	if !r.Configuration.DaysOld.IsUnknown() && !r.Configuration.DaysOld.IsNull() {
		*daysOld = r.Configuration.DaysOld.ValueString()
	} else {
		daysOld = nil
	}
	historyRange := new(string)
	if !r.Configuration.HistoryRange.IsUnknown() && !r.Configuration.HistoryRange.IsNull() {
		*historyRange = r.Configuration.HistoryRange.ValueString()
	} else {
		historyRange = nil
	}
	latitude := new(string)
	if !r.Configuration.Latitude.IsUnknown() && !r.Configuration.Latitude.IsNull() {
		*latitude = r.Configuration.Latitude.ValueString()
	} else {
		latitude = nil
	}
	longitude := new(string)
	if !r.Configuration.Longitude.IsUnknown() && !r.Configuration.Longitude.IsNull() {
		*longitude = r.Configuration.Longitude.ValueString()
	} else {
		longitude = nil
	}
	propertyType := new(string)
	if !r.Configuration.PropertyType.IsUnknown() && !r.Configuration.PropertyType.IsNull() {
		*propertyType = r.Configuration.PropertyType.ValueString()
	} else {
		propertyType = nil
	}
	radius := new(string)
	if !r.Configuration.Radius.IsUnknown() && !r.Configuration.Radius.IsNull() {
		*radius = r.Configuration.Radius.ValueString()
	} else {
		radius = nil
	}
	state := new(string)
	if !r.Configuration.State.IsUnknown() && !r.Configuration.State.IsNull() {
		*state = r.Configuration.State.ValueString()
	} else {
		state = nil
	}
	status := new(string)
	if !r.Configuration.Status.IsUnknown() && !r.Configuration.Status.IsNull() {
		*status = r.Configuration.Status.ValueString()
	} else {
		status = nil
	}
	zipcode := new(string)
	if !r.Configuration.Zipcode.IsUnknown() && !r.Configuration.Zipcode.IsNull() {
		*zipcode = r.Configuration.Zipcode.ValueString()
	} else {
		zipcode = nil
	}
	configuration := shared.SourceRentcastUpdate{
		Address:      address,
		APIKey:       apiKey,
		BathRooms:    bathRooms,
		Bedrooms:     bedrooms,
		City:         city,
		DataType:     dataType,
		DaysOld:      daysOld,
		HistoryRange: historyRange,
		Latitude:     latitude,
		Longitude:    longitude,
		PropertyType: propertyType,
		Radius:       radius,
		State:        state,
		Status:       status,
		Zipcode:      zipcode,
	}
	out := shared.SourceRentcastPutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
