// 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 *SourceAmazonSellerPartnerResourceModel) ToSharedSourceAmazonSellerPartnerCreateRequest() *shared.SourceAmazonSellerPartnerCreateRequest {
	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()

	accountType := new(shared.AWSSellerPartnerAccountType)
	if !r.Configuration.AccountType.IsUnknown() && !r.Configuration.AccountType.IsNull() {
		*accountType = shared.AWSSellerPartnerAccountType(r.Configuration.AccountType.ValueString())
	} else {
		accountType = nil
	}
	appID := new(string)
	if !r.Configuration.AppID.IsUnknown() && !r.Configuration.AppID.IsNull() {
		*appID = r.Configuration.AppID.ValueString()
	} else {
		appID = nil
	}
	awsEnvironment := new(shared.AWSEnvironment)
	if !r.Configuration.AwsEnvironment.IsUnknown() && !r.Configuration.AwsEnvironment.IsNull() {
		*awsEnvironment = shared.AWSEnvironment(r.Configuration.AwsEnvironment.ValueString())
	} else {
		awsEnvironment = nil
	}
	financialEventsStep := new(shared.FinancialEventsStepSizeInDays)
	if !r.Configuration.FinancialEventsStep.IsUnknown() && !r.Configuration.FinancialEventsStep.IsNull() {
		*financialEventsStep = shared.FinancialEventsStepSizeInDays(r.Configuration.FinancialEventsStep.ValueString())
	} else {
		financialEventsStep = nil
	}
	var lwaAppID string
	lwaAppID = r.Configuration.LwaAppID.ValueString()

	var lwaClientSecret string
	lwaClientSecret = r.Configuration.LwaClientSecret.ValueString()

	periodInDays := new(int64)
	if !r.Configuration.PeriodInDays.IsUnknown() && !r.Configuration.PeriodInDays.IsNull() {
		*periodInDays = r.Configuration.PeriodInDays.ValueInt64()
	} else {
		periodInDays = nil
	}
	var refreshToken string
	refreshToken = r.Configuration.RefreshToken.ValueString()

	region := new(shared.AWSRegion)
	if !r.Configuration.Region.IsUnknown() && !r.Configuration.Region.IsNull() {
		*region = shared.AWSRegion(r.Configuration.Region.ValueString())
	} else {
		region = nil
	}
	replicationEndDate := new(time.Time)
	if !r.Configuration.ReplicationEndDate.IsUnknown() && !r.Configuration.ReplicationEndDate.IsNull() {
		*replicationEndDate, _ = time.Parse(time.RFC3339Nano, r.Configuration.ReplicationEndDate.ValueString())
	} else {
		replicationEndDate = nil
	}
	replicationStartDate := new(time.Time)
	if !r.Configuration.ReplicationStartDate.IsUnknown() && !r.Configuration.ReplicationStartDate.IsNull() {
		*replicationStartDate, _ = time.Parse(time.RFC3339Nano, r.Configuration.ReplicationStartDate.ValueString())
	} else {
		replicationStartDate = nil
	}
	var reportOptionsList []shared.ReportOptions = []shared.ReportOptions{}
	for _, reportOptionsListItem := range r.Configuration.ReportOptionsList {
		var optionsList []shared.OptionsList = []shared.OptionsList{}
		for _, optionsListItem := range reportOptionsListItem.OptionsList {
			var optionName string
			optionName = optionsListItem.OptionName.ValueString()

			var optionValue string
			optionValue = optionsListItem.OptionValue.ValueString()

			optionsList = append(optionsList, shared.OptionsList{
				OptionName:  optionName,
				OptionValue: optionValue,
			})
		}
		reportName := shared.ReportName(reportOptionsListItem.ReportName.ValueString())
		var streamName string
		streamName = reportOptionsListItem.StreamName.ValueString()

		reportOptionsList = append(reportOptionsList, shared.ReportOptions{
			OptionsList: optionsList,
			ReportName:  reportName,
			StreamName:  streamName,
		})
	}
	waitToAvoidFatalErrors := new(bool)
	if !r.Configuration.WaitToAvoidFatalErrors.IsUnknown() && !r.Configuration.WaitToAvoidFatalErrors.IsNull() {
		*waitToAvoidFatalErrors = r.Configuration.WaitToAvoidFatalErrors.ValueBool()
	} else {
		waitToAvoidFatalErrors = nil
	}
	configuration := shared.SourceAmazonSellerPartner{
		AccountType:            accountType,
		AppID:                  appID,
		AwsEnvironment:         awsEnvironment,
		FinancialEventsStep:    financialEventsStep,
		LwaAppID:               lwaAppID,
		LwaClientSecret:        lwaClientSecret,
		PeriodInDays:           periodInDays,
		RefreshToken:           refreshToken,
		Region:                 region,
		ReplicationEndDate:     replicationEndDate,
		ReplicationStartDate:   replicationStartDate,
		ReportOptionsList:      reportOptionsList,
		WaitToAvoidFatalErrors: waitToAvoidFatalErrors,
	}
	secretID := new(string)
	if !r.SecretID.IsUnknown() && !r.SecretID.IsNull() {
		*secretID = r.SecretID.ValueString()
	} else {
		secretID = nil
	}
	out := shared.SourceAmazonSellerPartnerCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
		SecretID:      secretID,
	}
	return &out
}

func (r *SourceAmazonSellerPartnerResourceModel) 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 *SourceAmazonSellerPartnerResourceModel) ToSharedSourceAmazonSellerPartnerPutRequest() *shared.SourceAmazonSellerPartnerPutRequest {
	var name string
	name = r.Name.ValueString()

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

	accountType := new(shared.SourceAmazonSellerPartnerUpdateAWSSellerPartnerAccountType)
	if !r.Configuration.AccountType.IsUnknown() && !r.Configuration.AccountType.IsNull() {
		*accountType = shared.SourceAmazonSellerPartnerUpdateAWSSellerPartnerAccountType(r.Configuration.AccountType.ValueString())
	} else {
		accountType = nil
	}
	appID := new(string)
	if !r.Configuration.AppID.IsUnknown() && !r.Configuration.AppID.IsNull() {
		*appID = r.Configuration.AppID.ValueString()
	} else {
		appID = nil
	}
	awsEnvironment := new(shared.SourceAmazonSellerPartnerUpdateAWSEnvironment)
	if !r.Configuration.AwsEnvironment.IsUnknown() && !r.Configuration.AwsEnvironment.IsNull() {
		*awsEnvironment = shared.SourceAmazonSellerPartnerUpdateAWSEnvironment(r.Configuration.AwsEnvironment.ValueString())
	} else {
		awsEnvironment = nil
	}
	financialEventsStep := new(shared.SourceAmazonSellerPartnerUpdateFinancialEventsStepSizeInDays)
	if !r.Configuration.FinancialEventsStep.IsUnknown() && !r.Configuration.FinancialEventsStep.IsNull() {
		*financialEventsStep = shared.SourceAmazonSellerPartnerUpdateFinancialEventsStepSizeInDays(r.Configuration.FinancialEventsStep.ValueString())
	} else {
		financialEventsStep = nil
	}
	var lwaAppID string
	lwaAppID = r.Configuration.LwaAppID.ValueString()

	var lwaClientSecret string
	lwaClientSecret = r.Configuration.LwaClientSecret.ValueString()

	periodInDays := new(int64)
	if !r.Configuration.PeriodInDays.IsUnknown() && !r.Configuration.PeriodInDays.IsNull() {
		*periodInDays = r.Configuration.PeriodInDays.ValueInt64()
	} else {
		periodInDays = nil
	}
	var refreshToken string
	refreshToken = r.Configuration.RefreshToken.ValueString()

	region := new(shared.SourceAmazonSellerPartnerUpdateAWSRegion)
	if !r.Configuration.Region.IsUnknown() && !r.Configuration.Region.IsNull() {
		*region = shared.SourceAmazonSellerPartnerUpdateAWSRegion(r.Configuration.Region.ValueString())
	} else {
		region = nil
	}
	replicationEndDate := new(time.Time)
	if !r.Configuration.ReplicationEndDate.IsUnknown() && !r.Configuration.ReplicationEndDate.IsNull() {
		*replicationEndDate, _ = time.Parse(time.RFC3339Nano, r.Configuration.ReplicationEndDate.ValueString())
	} else {
		replicationEndDate = nil
	}
	replicationStartDate := new(time.Time)
	if !r.Configuration.ReplicationStartDate.IsUnknown() && !r.Configuration.ReplicationStartDate.IsNull() {
		*replicationStartDate, _ = time.Parse(time.RFC3339Nano, r.Configuration.ReplicationStartDate.ValueString())
	} else {
		replicationStartDate = nil
	}
	var reportOptionsList []shared.SourceAmazonSellerPartnerUpdateReportOptions = []shared.SourceAmazonSellerPartnerUpdateReportOptions{}
	for _, reportOptionsListItem := range r.Configuration.ReportOptionsList {
		var optionsList []shared.SourceAmazonSellerPartnerUpdateOptionsList = []shared.SourceAmazonSellerPartnerUpdateOptionsList{}
		for _, optionsListItem := range reportOptionsListItem.OptionsList {
			var optionName string
			optionName = optionsListItem.OptionName.ValueString()

			var optionValue string
			optionValue = optionsListItem.OptionValue.ValueString()

			optionsList = append(optionsList, shared.SourceAmazonSellerPartnerUpdateOptionsList{
				OptionName:  optionName,
				OptionValue: optionValue,
			})
		}
		reportName := shared.SourceAmazonSellerPartnerUpdateReportName(reportOptionsListItem.ReportName.ValueString())
		var streamName string
		streamName = reportOptionsListItem.StreamName.ValueString()

		reportOptionsList = append(reportOptionsList, shared.SourceAmazonSellerPartnerUpdateReportOptions{
			OptionsList: optionsList,
			ReportName:  reportName,
			StreamName:  streamName,
		})
	}
	waitToAvoidFatalErrors := new(bool)
	if !r.Configuration.WaitToAvoidFatalErrors.IsUnknown() && !r.Configuration.WaitToAvoidFatalErrors.IsNull() {
		*waitToAvoidFatalErrors = r.Configuration.WaitToAvoidFatalErrors.ValueBool()
	} else {
		waitToAvoidFatalErrors = nil
	}
	configuration := shared.SourceAmazonSellerPartnerUpdate{
		AccountType:            accountType,
		AppID:                  appID,
		AwsEnvironment:         awsEnvironment,
		FinancialEventsStep:    financialEventsStep,
		LwaAppID:               lwaAppID,
		LwaClientSecret:        lwaClientSecret,
		PeriodInDays:           periodInDays,
		RefreshToken:           refreshToken,
		Region:                 region,
		ReplicationEndDate:     replicationEndDate,
		ReplicationStartDate:   replicationStartDate,
		ReportOptionsList:      reportOptionsList,
		WaitToAvoidFatalErrors: waitToAvoidFatalErrors,
	}
	out := shared.SourceAmazonSellerPartnerPutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
