// 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 *SourceGoogleSheetsResourceModel) ToSharedSourceGoogleSheetsCreateRequest() *shared.SourceGoogleSheetsCreateRequest {
	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()

	allowLeadingNumbers := new(bool)
	if !r.Configuration.AllowLeadingNumbers.IsUnknown() && !r.Configuration.AllowLeadingNumbers.IsNull() {
		*allowLeadingNumbers = r.Configuration.AllowLeadingNumbers.ValueBool()
	} else {
		allowLeadingNumbers = nil
	}
	batchSize := new(int64)
	if !r.Configuration.BatchSize.IsUnknown() && !r.Configuration.BatchSize.IsNull() {
		*batchSize = r.Configuration.BatchSize.ValueInt64()
	} else {
		batchSize = nil
	}
	combineLetterNumberPairs := new(bool)
	if !r.Configuration.CombineLetterNumberPairs.IsUnknown() && !r.Configuration.CombineLetterNumberPairs.IsNull() {
		*combineLetterNumberPairs = r.Configuration.CombineLetterNumberPairs.ValueBool()
	} else {
		combineLetterNumberPairs = nil
	}
	combineNumberWordPairs := new(bool)
	if !r.Configuration.CombineNumberWordPairs.IsUnknown() && !r.Configuration.CombineNumberWordPairs.IsNull() {
		*combineNumberWordPairs = r.Configuration.CombineNumberWordPairs.ValueBool()
	} else {
		combineNumberWordPairs = nil
	}
	var credentials shared.SourceGoogleSheetsAuthentication
	var sourceGoogleSheetsAuthenticateViaGoogleOAuth *shared.SourceGoogleSheetsAuthenticateViaGoogleOAuth
	if r.Configuration.Credentials.AuthenticateViaGoogleOAuth != nil {
		var clientID string
		clientID = r.Configuration.Credentials.AuthenticateViaGoogleOAuth.ClientID.ValueString()

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

		var refreshToken string
		refreshToken = r.Configuration.Credentials.AuthenticateViaGoogleOAuth.RefreshToken.ValueString()

		sourceGoogleSheetsAuthenticateViaGoogleOAuth = &shared.SourceGoogleSheetsAuthenticateViaGoogleOAuth{
			ClientID:     clientID,
			ClientSecret: clientSecret,
			RefreshToken: refreshToken,
		}
	}
	if sourceGoogleSheetsAuthenticateViaGoogleOAuth != nil {
		credentials = shared.SourceGoogleSheetsAuthentication{
			SourceGoogleSheetsAuthenticateViaGoogleOAuth: sourceGoogleSheetsAuthenticateViaGoogleOAuth,
		}
	}
	var sourceGoogleSheetsServiceAccountKeyAuthentication *shared.SourceGoogleSheetsServiceAccountKeyAuthentication
	if r.Configuration.Credentials.ServiceAccountKeyAuthentication != nil {
		var serviceAccountInfo string
		serviceAccountInfo = r.Configuration.Credentials.ServiceAccountKeyAuthentication.ServiceAccountInfo.ValueString()

		sourceGoogleSheetsServiceAccountKeyAuthentication = &shared.SourceGoogleSheetsServiceAccountKeyAuthentication{
			ServiceAccountInfo: serviceAccountInfo,
		}
	}
	if sourceGoogleSheetsServiceAccountKeyAuthentication != nil {
		credentials = shared.SourceGoogleSheetsAuthentication{
			SourceGoogleSheetsServiceAccountKeyAuthentication: sourceGoogleSheetsServiceAccountKeyAuthentication,
		}
	}
	namesConversion := new(bool)
	if !r.Configuration.NamesConversion.IsUnknown() && !r.Configuration.NamesConversion.IsNull() {
		*namesConversion = r.Configuration.NamesConversion.ValueBool()
	} else {
		namesConversion = nil
	}
	removeLeadingTrailingUnderscores := new(bool)
	if !r.Configuration.RemoveLeadingTrailingUnderscores.IsUnknown() && !r.Configuration.RemoveLeadingTrailingUnderscores.IsNull() {
		*removeLeadingTrailingUnderscores = r.Configuration.RemoveLeadingTrailingUnderscores.ValueBool()
	} else {
		removeLeadingTrailingUnderscores = nil
	}
	removeSpecialCharacters := new(bool)
	if !r.Configuration.RemoveSpecialCharacters.IsUnknown() && !r.Configuration.RemoveSpecialCharacters.IsNull() {
		*removeSpecialCharacters = r.Configuration.RemoveSpecialCharacters.ValueBool()
	} else {
		removeSpecialCharacters = nil
	}
	var spreadsheetID string
	spreadsheetID = r.Configuration.SpreadsheetID.ValueString()

	var streamNameOverrides []shared.StreamNameOverrides = []shared.StreamNameOverrides{}
	for _, streamNameOverridesItem := range r.Configuration.StreamNameOverrides {
		var customStreamName string
		customStreamName = streamNameOverridesItem.CustomStreamName.ValueString()

		var sourceStreamName string
		sourceStreamName = streamNameOverridesItem.SourceStreamName.ValueString()

		streamNameOverrides = append(streamNameOverrides, shared.StreamNameOverrides{
			CustomStreamName: customStreamName,
			SourceStreamName: sourceStreamName,
		})
	}
	configuration := shared.SourceGoogleSheets{
		AllowLeadingNumbers:              allowLeadingNumbers,
		BatchSize:                        batchSize,
		CombineLetterNumberPairs:         combineLetterNumberPairs,
		CombineNumberWordPairs:           combineNumberWordPairs,
		Credentials:                      credentials,
		NamesConversion:                  namesConversion,
		RemoveLeadingTrailingUnderscores: removeLeadingTrailingUnderscores,
		RemoveSpecialCharacters:          removeSpecialCharacters,
		SpreadsheetID:                    spreadsheetID,
		StreamNameOverrides:              streamNameOverrides,
	}
	secretID := new(string)
	if !r.SecretID.IsUnknown() && !r.SecretID.IsNull() {
		*secretID = r.SecretID.ValueString()
	} else {
		secretID = nil
	}
	out := shared.SourceGoogleSheetsCreateRequest{
		Name:          name,
		DefinitionID:  definitionID,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
		SecretID:      secretID,
	}
	return &out
}

func (r *SourceGoogleSheetsResourceModel) 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 *SourceGoogleSheetsResourceModel) ToSharedSourceGoogleSheetsPutRequest() *shared.SourceGoogleSheetsPutRequest {
	var name string
	name = r.Name.ValueString()

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

	allowLeadingNumbers := new(bool)
	if !r.Configuration.AllowLeadingNumbers.IsUnknown() && !r.Configuration.AllowLeadingNumbers.IsNull() {
		*allowLeadingNumbers = r.Configuration.AllowLeadingNumbers.ValueBool()
	} else {
		allowLeadingNumbers = nil
	}
	batchSize := new(int64)
	if !r.Configuration.BatchSize.IsUnknown() && !r.Configuration.BatchSize.IsNull() {
		*batchSize = r.Configuration.BatchSize.ValueInt64()
	} else {
		batchSize = nil
	}
	combineLetterNumberPairs := new(bool)
	if !r.Configuration.CombineLetterNumberPairs.IsUnknown() && !r.Configuration.CombineLetterNumberPairs.IsNull() {
		*combineLetterNumberPairs = r.Configuration.CombineLetterNumberPairs.ValueBool()
	} else {
		combineLetterNumberPairs = nil
	}
	combineNumberWordPairs := new(bool)
	if !r.Configuration.CombineNumberWordPairs.IsUnknown() && !r.Configuration.CombineNumberWordPairs.IsNull() {
		*combineNumberWordPairs = r.Configuration.CombineNumberWordPairs.ValueBool()
	} else {
		combineNumberWordPairs = nil
	}
	var credentials shared.SourceGoogleSheetsUpdateAuthentication
	var sourceGoogleSheetsUpdateAuthenticateViaGoogleOAuth *shared.SourceGoogleSheetsUpdateAuthenticateViaGoogleOAuth
	if r.Configuration.Credentials.AuthenticateViaGoogleOAuth != nil {
		var clientID string
		clientID = r.Configuration.Credentials.AuthenticateViaGoogleOAuth.ClientID.ValueString()

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

		var refreshToken string
		refreshToken = r.Configuration.Credentials.AuthenticateViaGoogleOAuth.RefreshToken.ValueString()

		sourceGoogleSheetsUpdateAuthenticateViaGoogleOAuth = &shared.SourceGoogleSheetsUpdateAuthenticateViaGoogleOAuth{
			ClientID:     clientID,
			ClientSecret: clientSecret,
			RefreshToken: refreshToken,
		}
	}
	if sourceGoogleSheetsUpdateAuthenticateViaGoogleOAuth != nil {
		credentials = shared.SourceGoogleSheetsUpdateAuthentication{
			SourceGoogleSheetsUpdateAuthenticateViaGoogleOAuth: sourceGoogleSheetsUpdateAuthenticateViaGoogleOAuth,
		}
	}
	var sourceGoogleSheetsUpdateServiceAccountKeyAuthentication *shared.SourceGoogleSheetsUpdateServiceAccountKeyAuthentication
	if r.Configuration.Credentials.ServiceAccountKeyAuthentication != nil {
		var serviceAccountInfo string
		serviceAccountInfo = r.Configuration.Credentials.ServiceAccountKeyAuthentication.ServiceAccountInfo.ValueString()

		sourceGoogleSheetsUpdateServiceAccountKeyAuthentication = &shared.SourceGoogleSheetsUpdateServiceAccountKeyAuthentication{
			ServiceAccountInfo: serviceAccountInfo,
		}
	}
	if sourceGoogleSheetsUpdateServiceAccountKeyAuthentication != nil {
		credentials = shared.SourceGoogleSheetsUpdateAuthentication{
			SourceGoogleSheetsUpdateServiceAccountKeyAuthentication: sourceGoogleSheetsUpdateServiceAccountKeyAuthentication,
		}
	}
	namesConversion := new(bool)
	if !r.Configuration.NamesConversion.IsUnknown() && !r.Configuration.NamesConversion.IsNull() {
		*namesConversion = r.Configuration.NamesConversion.ValueBool()
	} else {
		namesConversion = nil
	}
	removeLeadingTrailingUnderscores := new(bool)
	if !r.Configuration.RemoveLeadingTrailingUnderscores.IsUnknown() && !r.Configuration.RemoveLeadingTrailingUnderscores.IsNull() {
		*removeLeadingTrailingUnderscores = r.Configuration.RemoveLeadingTrailingUnderscores.ValueBool()
	} else {
		removeLeadingTrailingUnderscores = nil
	}
	removeSpecialCharacters := new(bool)
	if !r.Configuration.RemoveSpecialCharacters.IsUnknown() && !r.Configuration.RemoveSpecialCharacters.IsNull() {
		*removeSpecialCharacters = r.Configuration.RemoveSpecialCharacters.ValueBool()
	} else {
		removeSpecialCharacters = nil
	}
	var spreadsheetID string
	spreadsheetID = r.Configuration.SpreadsheetID.ValueString()

	var streamNameOverrides []shared.SourceGoogleSheetsUpdateStreamNameOverrides = []shared.SourceGoogleSheetsUpdateStreamNameOverrides{}
	for _, streamNameOverridesItem := range r.Configuration.StreamNameOverrides {
		var customStreamName string
		customStreamName = streamNameOverridesItem.CustomStreamName.ValueString()

		var sourceStreamName string
		sourceStreamName = streamNameOverridesItem.SourceStreamName.ValueString()

		streamNameOverrides = append(streamNameOverrides, shared.SourceGoogleSheetsUpdateStreamNameOverrides{
			CustomStreamName: customStreamName,
			SourceStreamName: sourceStreamName,
		})
	}
	configuration := shared.SourceGoogleSheetsUpdate{
		AllowLeadingNumbers:              allowLeadingNumbers,
		BatchSize:                        batchSize,
		CombineLetterNumberPairs:         combineLetterNumberPairs,
		CombineNumberWordPairs:           combineNumberWordPairs,
		Credentials:                      credentials,
		NamesConversion:                  namesConversion,
		RemoveLeadingTrailingUnderscores: removeLeadingTrailingUnderscores,
		RemoveSpecialCharacters:          removeSpecialCharacters,
		SpreadsheetID:                    spreadsheetID,
		StreamNameOverrides:              streamNameOverrides,
	}
	out := shared.SourceGoogleSheetsPutRequest{
		Name:          name,
		WorkspaceID:   workspaceID,
		Configuration: configuration,
	}
	return &out
}
