// 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 *SourceOutbrainAmplifyResourceModel) ToSharedSourceOutbrainAmplifyCreateRequest() *shared.SourceOutbrainAmplifyCreateRequest {
	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()

	conversionCount := new(shared.DefinitionOfConversionCountInReports)
	if !r.Configuration.ConversionCount.IsUnknown() && !r.Configuration.ConversionCount.IsNull() {
		*conversionCount = shared.DefinitionOfConversionCountInReports(r.Configuration.ConversionCount.ValueString())
	} else {
		conversionCount = nil
	}
	var credentials shared.SourceOutbrainAmplifyAuthenticationMethod
	var sourceOutbrainAmplifyAccessToken *shared.SourceOutbrainAmplifyAccessToken
	if r.Configuration.Credentials.AccessToken != nil {
		var accessToken string
		accessToken = r.Configuration.Credentials.AccessToken.AccessToken.ValueString()

		sourceOutbrainAmplifyAccessToken = &shared.SourceOutbrainAmplifyAccessToken{
			AccessToken: accessToken,
		}
	}
	if sourceOutbrainAmplifyAccessToken != nil {
		credentials = shared.SourceOutbrainAmplifyAuthenticationMethod{
			SourceOutbrainAmplifyAccessToken: sourceOutbrainAmplifyAccessToken,
		}
	}
	var sourceOutbrainAmplifyUsernamePassword *shared.SourceOutbrainAmplifyUsernamePassword
	if r.Configuration.Credentials.UsernamePassword != nil {
		var password string
		password = r.Configuration.Credentials.UsernamePassword.Password.ValueString()

		var username string
		username = r.Configuration.Credentials.UsernamePassword.Username.ValueString()

		sourceOutbrainAmplifyUsernamePassword = &shared.SourceOutbrainAmplifyUsernamePassword{
			Password: password,
			Username: username,
		}
	}
	if sourceOutbrainAmplifyUsernamePassword != nil {
		credentials = shared.SourceOutbrainAmplifyAuthenticationMethod{
			SourceOutbrainAmplifyUsernamePassword: sourceOutbrainAmplifyUsernamePassword,
		}
	}
	endDate := new(string)
	if !r.Configuration.EndDate.IsUnknown() && !r.Configuration.EndDate.IsNull() {
		*endDate = r.Configuration.EndDate.ValueString()
	} else {
		endDate = nil
	}
	geoLocationBreakdown := new(shared.GranularityForGeoLocationRegion)
	if !r.Configuration.GeoLocationBreakdown.IsUnknown() && !r.Configuration.GeoLocationBreakdown.IsNull() {
		*geoLocationBreakdown = shared.GranularityForGeoLocationRegion(r.Configuration.GeoLocationBreakdown.ValueString())
	} else {
		geoLocationBreakdown = nil
	}
	reportGranularity := new(shared.GranularityForPeriodicReports)
	if !r.Configuration.ReportGranularity.IsUnknown() && !r.Configuration.ReportGranularity.IsNull() {
		*reportGranularity = shared.GranularityForPeriodicReports(r.Configuration.ReportGranularity.ValueString())
	} else {
		reportGranularity = nil
	}
	var startDate string
	startDate = r.Configuration.StartDate.ValueString()

	configuration := shared.SourceOutbrainAmplify{
		ConversionCount:      conversionCount,
		Credentials:          credentials,
		EndDate:              endDate,
		GeoLocationBreakdown: geoLocationBreakdown,
		ReportGranularity:    reportGranularity,
		StartDate:            startDate,
	}
	secretID := new(string)
	if !r.SecretID.IsUnknown() && !r.SecretID.IsNull() {
		*secretID = r.SecretID.ValueString()
	} else {
		secretID = nil
	}
	out := shared.SourceOutbrainAmplifyCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
		SecretID:      secretID,
	}
	return &out
}

func (r *SourceOutbrainAmplifyResourceModel) 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 *SourceOutbrainAmplifyResourceModel) ToSharedSourceOutbrainAmplifyPutRequest() *shared.SourceOutbrainAmplifyPutRequest {
	var name string
	name = r.Name.ValueString()

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

	conversionCount := new(shared.SourceOutbrainAmplifyUpdateDefinitionOfConversionCountInReports)
	if !r.Configuration.ConversionCount.IsUnknown() && !r.Configuration.ConversionCount.IsNull() {
		*conversionCount = shared.SourceOutbrainAmplifyUpdateDefinitionOfConversionCountInReports(r.Configuration.ConversionCount.ValueString())
	} else {
		conversionCount = nil
	}
	var credentials shared.SourceOutbrainAmplifyUpdateAuthenticationMethod
	var sourceOutbrainAmplifyUpdateAccessToken *shared.SourceOutbrainAmplifyUpdateAccessToken
	if r.Configuration.Credentials.AccessToken != nil {
		var accessToken string
		accessToken = r.Configuration.Credentials.AccessToken.AccessToken.ValueString()

		sourceOutbrainAmplifyUpdateAccessToken = &shared.SourceOutbrainAmplifyUpdateAccessToken{
			AccessToken: accessToken,
		}
	}
	if sourceOutbrainAmplifyUpdateAccessToken != nil {
		credentials = shared.SourceOutbrainAmplifyUpdateAuthenticationMethod{
			SourceOutbrainAmplifyUpdateAccessToken: sourceOutbrainAmplifyUpdateAccessToken,
		}
	}
	var sourceOutbrainAmplifyUpdateUsernamePassword *shared.SourceOutbrainAmplifyUpdateUsernamePassword
	if r.Configuration.Credentials.UsernamePassword != nil {
		var password string
		password = r.Configuration.Credentials.UsernamePassword.Password.ValueString()

		var username string
		username = r.Configuration.Credentials.UsernamePassword.Username.ValueString()

		sourceOutbrainAmplifyUpdateUsernamePassword = &shared.SourceOutbrainAmplifyUpdateUsernamePassword{
			Password: password,
			Username: username,
		}
	}
	if sourceOutbrainAmplifyUpdateUsernamePassword != nil {
		credentials = shared.SourceOutbrainAmplifyUpdateAuthenticationMethod{
			SourceOutbrainAmplifyUpdateUsernamePassword: sourceOutbrainAmplifyUpdateUsernamePassword,
		}
	}
	endDate := new(string)
	if !r.Configuration.EndDate.IsUnknown() && !r.Configuration.EndDate.IsNull() {
		*endDate = r.Configuration.EndDate.ValueString()
	} else {
		endDate = nil
	}
	geoLocationBreakdown := new(shared.SourceOutbrainAmplifyUpdateGranularityForGeoLocationRegion)
	if !r.Configuration.GeoLocationBreakdown.IsUnknown() && !r.Configuration.GeoLocationBreakdown.IsNull() {
		*geoLocationBreakdown = shared.SourceOutbrainAmplifyUpdateGranularityForGeoLocationRegion(r.Configuration.GeoLocationBreakdown.ValueString())
	} else {
		geoLocationBreakdown = nil
	}
	reportGranularity := new(shared.SourceOutbrainAmplifyUpdateGranularityForPeriodicReports)
	if !r.Configuration.ReportGranularity.IsUnknown() && !r.Configuration.ReportGranularity.IsNull() {
		*reportGranularity = shared.SourceOutbrainAmplifyUpdateGranularityForPeriodicReports(r.Configuration.ReportGranularity.ValueString())
	} else {
		reportGranularity = nil
	}
	var startDate string
	startDate = r.Configuration.StartDate.ValueString()

	configuration := shared.SourceOutbrainAmplifyUpdate{
		ConversionCount:      conversionCount,
		Credentials:          credentials,
		EndDate:              endDate,
		GeoLocationBreakdown: geoLocationBreakdown,
		ReportGranularity:    reportGranularity,
		StartDate:            startDate,
	}
	out := shared.SourceOutbrainAmplifyPutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
