// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Code generated by the Google Gen AI SDK generator DO NOT EDIT.

package genai

import (
	"context"
	"fmt"
	"iter"
	"log"
	"net/http"
	"strings"
	"sync"
)

func cancelTuningJobParametersToMldev(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromName := InternalGetValueByPath(fromObject, []string{"name"})
	if fromName != nil {
		InternalSetValueByPath(toObject, []string{"_url", "name"}, fromName)
	}

	return toObject, nil
}

func cancelTuningJobParametersToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromName := InternalGetValueByPath(fromObject, []string{"name"})
	if fromName != nil {
		InternalSetValueByPath(toObject, []string{"_url", "name"}, fromName)
	}

	return toObject, nil
}

func cancelTuningJobResponseFromMldev(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromSdkHttpResponse := InternalGetValueByPath(fromObject, []string{"sdkHttpResponse"})
	if fromSdkHttpResponse != nil {
		InternalSetValueByPath(toObject, []string{"sdkHttpResponse"}, fromSdkHttpResponse)
	}

	return toObject, nil
}

func cancelTuningJobResponseFromVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromSdkHttpResponse := InternalGetValueByPath(fromObject, []string{"sdkHttpResponse"})
	if fromSdkHttpResponse != nil {
		InternalSetValueByPath(toObject, []string{"sdkHttpResponse"}, fromSdkHttpResponse)
	}

	return toObject, nil
}

func createTuningJobConfigToMldev(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	if InternalGetValueByPath(fromObject, []string{"validationDataset"}) != nil {
		return nil, fmt.Errorf("validationDataset parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	fromTunedModelDisplayName := InternalGetValueByPath(fromObject, []string{"tunedModelDisplayName"})
	if fromTunedModelDisplayName != nil {
		InternalSetValueByPath(parentObject, []string{"displayName"}, fromTunedModelDisplayName)
	}

	if InternalGetValueByPath(fromObject, []string{"description"}) != nil {
		return nil, fmt.Errorf("description parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	fromEpochCount := InternalGetValueByPath(fromObject, []string{"epochCount"})
	if fromEpochCount != nil {
		InternalSetValueByPath(parentObject, []string{"tuningTask", "hyperparameters", "epochCount"}, fromEpochCount)
	}

	fromLearningRateMultiplier := InternalGetValueByPath(fromObject, []string{"learningRateMultiplier"})
	if fromLearningRateMultiplier != nil {
		InternalSetValueByPath(toObject, []string{"tuningTask", "hyperparameters", "learningRateMultiplier"}, fromLearningRateMultiplier)
	}

	if InternalGetValueByPath(fromObject, []string{"exportLastCheckpointOnly"}) != nil {
		return nil, fmt.Errorf("exportLastCheckpointOnly parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"preTunedModelCheckpointId"}) != nil {
		return nil, fmt.Errorf("preTunedModelCheckpointId parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"adapterSize"}) != nil {
		return nil, fmt.Errorf("adapterSize parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"tuningMode"}) != nil {
		return nil, fmt.Errorf("tuningMode parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"customBaseModel"}) != nil {
		return nil, fmt.Errorf("customBaseModel parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	fromBatchSize := InternalGetValueByPath(fromObject, []string{"batchSize"})
	if fromBatchSize != nil {
		InternalSetValueByPath(parentObject, []string{"tuningTask", "hyperparameters", "batchSize"}, fromBatchSize)
	}

	fromLearningRate := InternalGetValueByPath(fromObject, []string{"learningRate"})
	if fromLearningRate != nil {
		InternalSetValueByPath(parentObject, []string{"tuningTask", "hyperparameters", "learningRate"}, fromLearningRate)
	}

	if InternalGetValueByPath(fromObject, []string{"labels"}) != nil {
		return nil, fmt.Errorf("labels parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"beta"}) != nil {
		return nil, fmt.Errorf("beta parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"baseTeacherModel"}) != nil {
		return nil, fmt.Errorf("baseTeacherModel parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"tunedTeacherModelSource"}) != nil {
		return nil, fmt.Errorf("tunedTeacherModelSource parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"sftLossWeightMultiplier"}) != nil {
		return nil, fmt.Errorf("sftLossWeightMultiplier parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"outputUri"}) != nil {
		return nil, fmt.Errorf("outputUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"encryptionSpec"}) != nil {
		return nil, fmt.Errorf("encryptionSpec parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"rewardConfig"}) != nil {
		return nil, fmt.Errorf("rewardConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"compositeRewardConfig"}) != nil {
		return nil, fmt.Errorf("compositeRewardConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"samplesPerPrompt"}) != nil {
		return nil, fmt.Errorf("samplesPerPrompt parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"evaluateInterval"}) != nil {
		return nil, fmt.Errorf("evaluateInterval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"checkpointInterval"}) != nil {
		return nil, fmt.Errorf("checkpointInterval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"maxOutputTokens"}) != nil {
		return nil, fmt.Errorf("maxOutputTokens parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"thinkingLevel"}) != nil {
		return nil, fmt.Errorf("thinkingLevel parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"validationDatasetUri"}) != nil {
		return nil, fmt.Errorf("validationDatasetUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	return toObject, nil
}

func createTuningJobConfigToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	var discriminatorValidationDataset any = InternalGetValueByPath(rootObject, []string{"config", "method"})
	if discriminatorValidationDataset == nil {
		discriminatorValidationDataset = "SUPERVISED_FINE_TUNING"
	}
	if discriminatorValidationDataset.(string) == "SUPERVISED_FINE_TUNING" {
		fromValidationDataset := InternalGetValueByPath(fromObject, []string{"validationDataset"})
		if fromValidationDataset != nil {
			fromValidationDataset, err = tuningValidationDatasetToVertex(fromValidationDataset.(map[string]any), toObject, rootObject)
			if err != nil {
				return nil, err
			}

			InternalSetValueByPath(parentObject, []string{"supervisedTuningSpec"}, fromValidationDataset)
		}
	} else if discriminatorValidationDataset.(string) == "PREFERENCE_TUNING" {
		fromValidationDataset := InternalGetValueByPath(fromObject, []string{"validationDataset"})
		if fromValidationDataset != nil {
			fromValidationDataset, err = tuningValidationDatasetToVertex(fromValidationDataset.(map[string]any), toObject, rootObject)
			if err != nil {
				return nil, err
			}

			InternalSetValueByPath(parentObject, []string{"preferenceOptimizationSpec"}, fromValidationDataset)
		}
	} else if discriminatorValidationDataset.(string) == "DISTILLATION" {
		fromValidationDataset := InternalGetValueByPath(fromObject, []string{"validationDataset"})
		if fromValidationDataset != nil {
			fromValidationDataset, err = tuningValidationDatasetToVertex(fromValidationDataset.(map[string]any), toObject, rootObject)
			if err != nil {
				return nil, err
			}

			InternalSetValueByPath(parentObject, []string{"distillationSpec"}, fromValidationDataset)
		}
	} else if discriminatorValidationDataset.(string) == "REINFORCEMENT_TUNING" {
		fromValidationDataset := InternalGetValueByPath(fromObject, []string{"validationDataset"})
		if fromValidationDataset != nil {
			fromValidationDataset, err = tuningValidationDatasetToVertex(fromValidationDataset.(map[string]any), toObject, rootObject)
			if err != nil {
				return nil, err
			}

			InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec"}, fromValidationDataset)
		}
	}

	fromTunedModelDisplayName := InternalGetValueByPath(fromObject, []string{"tunedModelDisplayName"})
	if fromTunedModelDisplayName != nil {
		InternalSetValueByPath(parentObject, []string{"tunedModelDisplayName"}, fromTunedModelDisplayName)
	}

	fromDescription := InternalGetValueByPath(fromObject, []string{"description"})
	if fromDescription != nil {
		InternalSetValueByPath(parentObject, []string{"description"}, fromDescription)
	}

	var discriminatorEpochCount any = InternalGetValueByPath(rootObject, []string{"config", "method"})
	if discriminatorEpochCount == nil {
		discriminatorEpochCount = "SUPERVISED_FINE_TUNING"
	}
	if discriminatorEpochCount.(string) == "SUPERVISED_FINE_TUNING" {
		fromEpochCount := InternalGetValueByPath(fromObject, []string{"epochCount"})
		if fromEpochCount != nil {
			InternalSetValueByPath(parentObject, []string{"supervisedTuningSpec", "hyperParameters", "epochCount"}, fromEpochCount)
		}
	} else if discriminatorEpochCount.(string) == "PREFERENCE_TUNING" {
		fromEpochCount := InternalGetValueByPath(fromObject, []string{"epochCount"})
		if fromEpochCount != nil {
			InternalSetValueByPath(parentObject, []string{"preferenceOptimizationSpec", "hyperParameters", "epochCount"}, fromEpochCount)
		}
	} else if discriminatorEpochCount.(string) == "DISTILLATION" {
		fromEpochCount := InternalGetValueByPath(fromObject, []string{"epochCount"})
		if fromEpochCount != nil {
			InternalSetValueByPath(parentObject, []string{"distillationSpec", "hyperParameters", "epochCount"}, fromEpochCount)
		}
	} else if discriminatorEpochCount.(string) == "REINFORCEMENT_TUNING" {
		fromEpochCount := InternalGetValueByPath(fromObject, []string{"epochCount"})
		if fromEpochCount != nil {
			InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "hyperParameters", "epochCount"}, fromEpochCount)
		}
	}

	var discriminatorLearningRateMultiplier any = InternalGetValueByPath(rootObject, []string{"config", "method"})
	if discriminatorLearningRateMultiplier == nil {
		discriminatorLearningRateMultiplier = "SUPERVISED_FINE_TUNING"
	}
	if discriminatorLearningRateMultiplier.(string) == "SUPERVISED_FINE_TUNING" {
		fromLearningRateMultiplier := InternalGetValueByPath(fromObject, []string{"learningRateMultiplier"})
		if fromLearningRateMultiplier != nil {
			InternalSetValueByPath(parentObject, []string{"supervisedTuningSpec", "hyperParameters", "learningRateMultiplier"}, fromLearningRateMultiplier)
		}
	} else if discriminatorLearningRateMultiplier.(string) == "PREFERENCE_TUNING" {
		fromLearningRateMultiplier := InternalGetValueByPath(fromObject, []string{"learningRateMultiplier"})
		if fromLearningRateMultiplier != nil {
			InternalSetValueByPath(parentObject, []string{"preferenceOptimizationSpec", "hyperParameters", "learningRateMultiplier"}, fromLearningRateMultiplier)
		}
	} else if discriminatorLearningRateMultiplier.(string) == "DISTILLATION" {
		fromLearningRateMultiplier := InternalGetValueByPath(fromObject, []string{"learningRateMultiplier"})
		if fromLearningRateMultiplier != nil {
			InternalSetValueByPath(parentObject, []string{"distillationSpec", "hyperParameters", "learningRateMultiplier"}, fromLearningRateMultiplier)
		}
	} else if discriminatorLearningRateMultiplier.(string) == "REINFORCEMENT_TUNING" {
		fromLearningRateMultiplier := InternalGetValueByPath(fromObject, []string{"learningRateMultiplier"})
		if fromLearningRateMultiplier != nil {
			InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "hyperParameters", "learningRateMultiplier"}, fromLearningRateMultiplier)
		}
	}

	var discriminatorExportLastCheckpointOnly any = InternalGetValueByPath(rootObject, []string{"config", "method"})
	if discriminatorExportLastCheckpointOnly == nil {
		discriminatorExportLastCheckpointOnly = "SUPERVISED_FINE_TUNING"
	}
	if discriminatorExportLastCheckpointOnly.(string) == "SUPERVISED_FINE_TUNING" {
		fromExportLastCheckpointOnly := InternalGetValueByPath(fromObject, []string{"exportLastCheckpointOnly"})
		if fromExportLastCheckpointOnly != nil {
			InternalSetValueByPath(parentObject, []string{"supervisedTuningSpec", "exportLastCheckpointOnly"}, fromExportLastCheckpointOnly)
		}
	} else if discriminatorExportLastCheckpointOnly.(string) == "PREFERENCE_TUNING" {
		fromExportLastCheckpointOnly := InternalGetValueByPath(fromObject, []string{"exportLastCheckpointOnly"})
		if fromExportLastCheckpointOnly != nil {
			InternalSetValueByPath(parentObject, []string{"preferenceOptimizationSpec", "exportLastCheckpointOnly"}, fromExportLastCheckpointOnly)
		}
	} else if discriminatorExportLastCheckpointOnly.(string) == "DISTILLATION" {
		fromExportLastCheckpointOnly := InternalGetValueByPath(fromObject, []string{"exportLastCheckpointOnly"})
		if fromExportLastCheckpointOnly != nil {
			InternalSetValueByPath(parentObject, []string{"distillationSpec", "exportLastCheckpointOnly"}, fromExportLastCheckpointOnly)
		}
	}

	var discriminatorAdapterSize any = InternalGetValueByPath(rootObject, []string{"config", "method"})
	if discriminatorAdapterSize == nil {
		discriminatorAdapterSize = "SUPERVISED_FINE_TUNING"
	}
	if discriminatorAdapterSize.(string) == "SUPERVISED_FINE_TUNING" {
		fromAdapterSize := InternalGetValueByPath(fromObject, []string{"adapterSize"})
		if fromAdapterSize != nil {
			InternalSetValueByPath(parentObject, []string{"supervisedTuningSpec", "hyperParameters", "adapterSize"}, fromAdapterSize)
		}
	} else if discriminatorAdapterSize.(string) == "PREFERENCE_TUNING" {
		fromAdapterSize := InternalGetValueByPath(fromObject, []string{"adapterSize"})
		if fromAdapterSize != nil {
			InternalSetValueByPath(parentObject, []string{"preferenceOptimizationSpec", "hyperParameters", "adapterSize"}, fromAdapterSize)
		}
	} else if discriminatorAdapterSize.(string) == "DISTILLATION" {
		fromAdapterSize := InternalGetValueByPath(fromObject, []string{"adapterSize"})
		if fromAdapterSize != nil {
			InternalSetValueByPath(parentObject, []string{"distillationSpec", "hyperParameters", "adapterSize"}, fromAdapterSize)
		}
	} else if discriminatorAdapterSize.(string) == "REINFORCEMENT_TUNING" {
		fromAdapterSize := InternalGetValueByPath(fromObject, []string{"adapterSize"})
		if fromAdapterSize != nil {
			InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "hyperParameters", "adapterSize"}, fromAdapterSize)
		}
	}

	var discriminatorTuningMode any = InternalGetValueByPath(rootObject, []string{"config", "method"})
	if discriminatorTuningMode == nil {
		discriminatorTuningMode = "SUPERVISED_FINE_TUNING"
	}
	if discriminatorTuningMode.(string) == "SUPERVISED_FINE_TUNING" {
		fromTuningMode := InternalGetValueByPath(fromObject, []string{"tuningMode"})
		if fromTuningMode != nil {
			InternalSetValueByPath(parentObject, []string{"supervisedTuningSpec", "tuningMode"}, fromTuningMode)
		}
	} else if discriminatorTuningMode.(string) == "DISTILLATION" {
		fromTuningMode := InternalGetValueByPath(fromObject, []string{"tuningMode"})
		if fromTuningMode != nil {
			InternalSetValueByPath(parentObject, []string{"distillationSpec", "tuningMode"}, fromTuningMode)
		}
	}

	fromCustomBaseModel := InternalGetValueByPath(fromObject, []string{"customBaseModel"})
	if fromCustomBaseModel != nil {
		InternalSetValueByPath(parentObject, []string{"customBaseModel"}, fromCustomBaseModel)
	}

	var discriminatorBatchSize any = InternalGetValueByPath(rootObject, []string{"config", "method"})
	if discriminatorBatchSize == nil {
		discriminatorBatchSize = "SUPERVISED_FINE_TUNING"
	}
	if discriminatorBatchSize.(string) == "SUPERVISED_FINE_TUNING" {
		fromBatchSize := InternalGetValueByPath(fromObject, []string{"batchSize"})
		if fromBatchSize != nil {
			InternalSetValueByPath(parentObject, []string{"supervisedTuningSpec", "hyperParameters", "batchSize"}, fromBatchSize)
		}
	} else if discriminatorBatchSize.(string) == "DISTILLATION" {
		fromBatchSize := InternalGetValueByPath(fromObject, []string{"batchSize"})
		if fromBatchSize != nil {
			InternalSetValueByPath(parentObject, []string{"distillationSpec", "hyperParameters", "batchSize"}, fromBatchSize)
		}
	} else if discriminatorBatchSize.(string) == "REINFORCEMENT_TUNING" {
		fromBatchSize := InternalGetValueByPath(fromObject, []string{"batchSize"})
		if fromBatchSize != nil {
			InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "hyperParameters", "batchSize"}, fromBatchSize)
		}
	}

	var discriminatorLearningRate any = InternalGetValueByPath(rootObject, []string{"config", "method"})
	if discriminatorLearningRate == nil {
		discriminatorLearningRate = "SUPERVISED_FINE_TUNING"
	}
	if discriminatorLearningRate.(string) == "SUPERVISED_FINE_TUNING" {
		fromLearningRate := InternalGetValueByPath(fromObject, []string{"learningRate"})
		if fromLearningRate != nil {
			InternalSetValueByPath(parentObject, []string{"supervisedTuningSpec", "hyperParameters", "learningRate"}, fromLearningRate)
		}
	} else if discriminatorLearningRate.(string) == "DISTILLATION" {
		fromLearningRate := InternalGetValueByPath(fromObject, []string{"learningRate"})
		if fromLearningRate != nil {
			InternalSetValueByPath(parentObject, []string{"distillationSpec", "hyperParameters", "learningRate"}, fromLearningRate)
		}
	}

	fromLabels := InternalGetValueByPath(fromObject, []string{"labels"})
	if fromLabels != nil {
		InternalSetValueByPath(parentObject, []string{"labels"}, fromLabels)
	}

	fromBeta := InternalGetValueByPath(fromObject, []string{"beta"})
	if fromBeta != nil {
		InternalSetValueByPath(parentObject, []string{"preferenceOptimizationSpec", "hyperParameters", "beta"}, fromBeta)
	}

	fromBaseTeacherModel := InternalGetValueByPath(fromObject, []string{"baseTeacherModel"})
	if fromBaseTeacherModel != nil {
		InternalSetValueByPath(parentObject, []string{"distillationSpec", "baseTeacherModel"}, fromBaseTeacherModel)
	}

	fromTunedTeacherModelSource := InternalGetValueByPath(fromObject, []string{"tunedTeacherModelSource"})
	if fromTunedTeacherModelSource != nil {
		InternalSetValueByPath(parentObject, []string{"distillationSpec", "tunedTeacherModelSource"}, fromTunedTeacherModelSource)
	}

	fromSftLossWeightMultiplier := InternalGetValueByPath(fromObject, []string{"sftLossWeightMultiplier"})
	if fromSftLossWeightMultiplier != nil {
		InternalSetValueByPath(parentObject, []string{"distillationSpec", "hyperParameters", "sftLossWeightMultiplier"}, fromSftLossWeightMultiplier)
	}

	fromOutputUri := InternalGetValueByPath(fromObject, []string{"outputUri"})
	if fromOutputUri != nil {
		InternalSetValueByPath(parentObject, []string{"outputUri"}, fromOutputUri)
	}

	fromEncryptionSpec := InternalGetValueByPath(fromObject, []string{"encryptionSpec"})
	if fromEncryptionSpec != nil {
		InternalSetValueByPath(parentObject, []string{"encryptionSpec"}, fromEncryptionSpec)
	}

	fromRewardConfig := InternalGetValueByPath(fromObject, []string{"rewardConfig"})
	if fromRewardConfig != nil {
		InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "singleRewardConfig"}, fromRewardConfig)
	}

	fromCompositeRewardConfig := InternalGetValueByPath(fromObject, []string{"compositeRewardConfig"})
	if fromCompositeRewardConfig != nil {
		InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "compositeRewardConfig"}, fromCompositeRewardConfig)
	}

	fromSamplesPerPrompt := InternalGetValueByPath(fromObject, []string{"samplesPerPrompt"})
	if fromSamplesPerPrompt != nil {
		InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "hyperParameters", "samplesPerPrompt"}, fromSamplesPerPrompt)
	}

	fromEvaluateInterval := InternalGetValueByPath(fromObject, []string{"evaluateInterval"})
	if fromEvaluateInterval != nil {
		InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "hyperParameters", "evaluateInterval"}, fromEvaluateInterval)
	}

	fromCheckpointInterval := InternalGetValueByPath(fromObject, []string{"checkpointInterval"})
	if fromCheckpointInterval != nil {
		InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "hyperParameters", "checkpointInterval"}, fromCheckpointInterval)
	}

	fromMaxOutputTokens := InternalGetValueByPath(fromObject, []string{"maxOutputTokens"})
	if fromMaxOutputTokens != nil {
		InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "hyperParameters", "maxOutputTokens"}, fromMaxOutputTokens)
	}

	fromThinkingLevel := InternalGetValueByPath(fromObject, []string{"thinkingLevel"})
	if fromThinkingLevel != nil {
		InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "hyperParameters", "thinkingLevel"}, fromThinkingLevel)
	}

	fromValidationDatasetUri := InternalGetValueByPath(fromObject, []string{"validationDatasetUri"})
	if fromValidationDatasetUri != nil {
		InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "validationDatasetUri"}, fromValidationDatasetUri)
	}

	return toObject, nil
}

func createTuningJobParametersPrivateToMldev(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromBaseModel := InternalGetValueByPath(fromObject, []string{"baseModel"})
	if fromBaseModel != nil {
		InternalSetValueByPath(toObject, []string{"baseModel"}, fromBaseModel)
	}

	fromPreTunedModel := InternalGetValueByPath(fromObject, []string{"preTunedModel"})
	if fromPreTunedModel != nil {
		InternalSetValueByPath(toObject, []string{"preTunedModel"}, fromPreTunedModel)
	}

	fromTrainingDataset := InternalGetValueByPath(fromObject, []string{"trainingDataset"})
	if fromTrainingDataset != nil {
		_, err = tuningDatasetToMldev(fromTrainingDataset.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}
	}

	fromConfig := InternalGetValueByPath(fromObject, []string{"config"})
	if fromConfig != nil {
		_, err = createTuningJobConfigToMldev(fromConfig.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}
	}

	return toObject, nil
}

func createTuningJobParametersPrivateToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromBaseModel := InternalGetValueByPath(fromObject, []string{"baseModel"})
	if fromBaseModel != nil {
		InternalSetValueByPath(toObject, []string{"baseModel"}, fromBaseModel)
	}

	fromPreTunedModel := InternalGetValueByPath(fromObject, []string{"preTunedModel"})
	if fromPreTunedModel != nil {
		InternalSetValueByPath(toObject, []string{"preTunedModel"}, fromPreTunedModel)
	}

	fromTrainingDataset := InternalGetValueByPath(fromObject, []string{"trainingDataset"})
	if fromTrainingDataset != nil {
		_, err = tuningDatasetToVertex(fromTrainingDataset.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}
	}

	fromConfig := InternalGetValueByPath(fromObject, []string{"config"})
	if fromConfig != nil {
		_, err = createTuningJobConfigToVertex(fromConfig.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}
	}

	return toObject, nil
}

func distillationHyperParametersFromVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromAdapterSize := InternalGetValueByPath(fromObject, []string{"adapterSize"})
	if fromAdapterSize != nil {
		InternalSetValueByPath(toObject, []string{"adapterSize"}, fromAdapterSize)
	}

	fromEpochCount := InternalGetValueByPath(fromObject, []string{"epochCount"})
	if fromEpochCount != nil {
		InternalSetValueByPath(toObject, []string{"epochCount"}, fromEpochCount)
	}

	fromLearningRateMultiplier := InternalGetValueByPath(fromObject, []string{"learningRateMultiplier"})
	if fromLearningRateMultiplier != nil {
		InternalSetValueByPath(toObject, []string{"learningRateMultiplier"}, fromLearningRateMultiplier)
	}

	fromGenerationConfig := InternalGetValueByPath(fromObject, []string{"generationConfig"})
	if fromGenerationConfig != nil {
		fromGenerationConfig, err = generationConfigFromVertex(fromGenerationConfig.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"generationConfig"}, fromGenerationConfig)
	}

	fromLearningRate := InternalGetValueByPath(fromObject, []string{"learningRate"})
	if fromLearningRate != nil {
		InternalSetValueByPath(toObject, []string{"learningRate"}, fromLearningRate)
	}

	fromBatchSize := InternalGetValueByPath(fromObject, []string{"batchSize"})
	if fromBatchSize != nil {
		InternalSetValueByPath(toObject, []string{"batchSize"}, fromBatchSize)
	}

	return toObject, nil
}

func distillationSamplingSpecFromVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromBaseTeacherModel := InternalGetValueByPath(fromObject, []string{"baseTeacherModel"})
	if fromBaseTeacherModel != nil {
		InternalSetValueByPath(toObject, []string{"baseTeacherModel"}, fromBaseTeacherModel)
	}

	fromTunedTeacherModelSource := InternalGetValueByPath(fromObject, []string{"tunedTeacherModelSource"})
	if fromTunedTeacherModelSource != nil {
		InternalSetValueByPath(toObject, []string{"tunedTeacherModelSource"}, fromTunedTeacherModelSource)
	}

	fromValidationDatasetUri := InternalGetValueByPath(fromObject, []string{"validationDatasetUri"})
	if fromValidationDatasetUri != nil {
		InternalSetValueByPath(toObject, []string{"validationDatasetUri"}, fromValidationDatasetUri)
	}

	fromPromptDatasetUri := InternalGetValueByPath(fromObject, []string{"promptDatasetUri"})
	if fromPromptDatasetUri != nil {
		InternalSetValueByPath(toObject, []string{"promptDatasetUri"}, fromPromptDatasetUri)
	}

	fromHyperparameters := InternalGetValueByPath(fromObject, []string{"hyperparameters"})
	if fromHyperparameters != nil {
		fromHyperparameters, err = distillationHyperParametersFromVertex(fromHyperparameters.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"hyperparameters"}, fromHyperparameters)
	}

	return toObject, nil
}

func distillationSpecFromVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromPromptDatasetUri := InternalGetValueByPath(fromObject, []string{"promptDatasetUri"})
	if fromPromptDatasetUri != nil {
		InternalSetValueByPath(toObject, []string{"promptDatasetUri"}, fromPromptDatasetUri)
	}

	fromBaseTeacherModel := InternalGetValueByPath(fromObject, []string{"baseTeacherModel"})
	if fromBaseTeacherModel != nil {
		InternalSetValueByPath(toObject, []string{"baseTeacherModel"}, fromBaseTeacherModel)
	}

	fromHyperParameters := InternalGetValueByPath(fromObject, []string{"hyperParameters"})
	if fromHyperParameters != nil {
		fromHyperParameters, err = distillationHyperParametersFromVertex(fromHyperParameters.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"hyperParameters"}, fromHyperParameters)
	}

	fromPipelineRootDirectory := InternalGetValueByPath(fromObject, []string{"pipelineRootDirectory"})
	if fromPipelineRootDirectory != nil {
		InternalSetValueByPath(toObject, []string{"pipelineRootDirectory"}, fromPipelineRootDirectory)
	}

	fromStudentModel := InternalGetValueByPath(fromObject, []string{"studentModel"})
	if fromStudentModel != nil {
		InternalSetValueByPath(toObject, []string{"studentModel"}, fromStudentModel)
	}

	fromTrainingDatasetUri := InternalGetValueByPath(fromObject, []string{"trainingDatasetUri"})
	if fromTrainingDatasetUri != nil {
		InternalSetValueByPath(toObject, []string{"trainingDatasetUri"}, fromTrainingDatasetUri)
	}

	fromTunedTeacherModelSource := InternalGetValueByPath(fromObject, []string{"tunedTeacherModelSource"})
	if fromTunedTeacherModelSource != nil {
		InternalSetValueByPath(toObject, []string{"tunedTeacherModelSource"}, fromTunedTeacherModelSource)
	}

	fromValidationDatasetUri := InternalGetValueByPath(fromObject, []string{"validationDatasetUri"})
	if fromValidationDatasetUri != nil {
		InternalSetValueByPath(toObject, []string{"validationDatasetUri"}, fromValidationDatasetUri)
	}

	fromTuningMode := InternalGetValueByPath(fromObject, []string{"tuningMode"})
	if fromTuningMode != nil {
		InternalSetValueByPath(toObject, []string{"tuningMode"}, fromTuningMode)
	}

	return toObject, nil
}

func generationConfigFromVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromModelSelectionConfig := InternalGetValueByPath(fromObject, []string{"modelConfig"})
	if fromModelSelectionConfig != nil {
		InternalSetValueByPath(toObject, []string{"modelSelectionConfig"}, fromModelSelectionConfig)
	}

	fromResponseJsonSchema := InternalGetValueByPath(fromObject, []string{"responseJsonSchema"})
	if fromResponseJsonSchema != nil {
		InternalSetValueByPath(toObject, []string{"responseJsonSchema"}, fromResponseJsonSchema)
	}

	fromAudioTimestamp := InternalGetValueByPath(fromObject, []string{"audioTimestamp"})
	if fromAudioTimestamp != nil {
		InternalSetValueByPath(toObject, []string{"audioTimestamp"}, fromAudioTimestamp)
	}

	fromCandidateCount := InternalGetValueByPath(fromObject, []string{"candidateCount"})
	if fromCandidateCount != nil {
		InternalSetValueByPath(toObject, []string{"candidateCount"}, fromCandidateCount)
	}

	fromEnableAffectiveDialog := InternalGetValueByPath(fromObject, []string{"enableAffectiveDialog"})
	if fromEnableAffectiveDialog != nil {
		InternalSetValueByPath(toObject, []string{"enableAffectiveDialog"}, fromEnableAffectiveDialog)
	}

	fromFrequencyPenalty := InternalGetValueByPath(fromObject, []string{"frequencyPenalty"})
	if fromFrequencyPenalty != nil {
		InternalSetValueByPath(toObject, []string{"frequencyPenalty"}, fromFrequencyPenalty)
	}

	fromLogprobs := InternalGetValueByPath(fromObject, []string{"logprobs"})
	if fromLogprobs != nil {
		InternalSetValueByPath(toObject, []string{"logprobs"}, fromLogprobs)
	}

	fromMaxOutputTokens := InternalGetValueByPath(fromObject, []string{"maxOutputTokens"})
	if fromMaxOutputTokens != nil {
		InternalSetValueByPath(toObject, []string{"maxOutputTokens"}, fromMaxOutputTokens)
	}

	fromMediaResolution := InternalGetValueByPath(fromObject, []string{"mediaResolution"})
	if fromMediaResolution != nil {
		InternalSetValueByPath(toObject, []string{"mediaResolution"}, fromMediaResolution)
	}

	fromPresencePenalty := InternalGetValueByPath(fromObject, []string{"presencePenalty"})
	if fromPresencePenalty != nil {
		InternalSetValueByPath(toObject, []string{"presencePenalty"}, fromPresencePenalty)
	}

	fromResponseLogprobs := InternalGetValueByPath(fromObject, []string{"responseLogprobs"})
	if fromResponseLogprobs != nil {
		InternalSetValueByPath(toObject, []string{"responseLogprobs"}, fromResponseLogprobs)
	}

	fromResponseMimeType := InternalGetValueByPath(fromObject, []string{"responseMimeType"})
	if fromResponseMimeType != nil {
		InternalSetValueByPath(toObject, []string{"responseMimeType"}, fromResponseMimeType)
	}

	fromResponseModalities := InternalGetValueByPath(fromObject, []string{"responseModalities"})
	if fromResponseModalities != nil {
		InternalSetValueByPath(toObject, []string{"responseModalities"}, fromResponseModalities)
	}

	fromResponseSchema := InternalGetValueByPath(fromObject, []string{"responseSchema"})
	if fromResponseSchema != nil {
		InternalSetValueByPath(toObject, []string{"responseSchema"}, fromResponseSchema)
	}

	fromRoutingConfig := InternalGetValueByPath(fromObject, []string{"routingConfig"})
	if fromRoutingConfig != nil {
		InternalSetValueByPath(toObject, []string{"routingConfig"}, fromRoutingConfig)
	}

	fromSeed := InternalGetValueByPath(fromObject, []string{"seed"})
	if fromSeed != nil {
		InternalSetValueByPath(toObject, []string{"seed"}, fromSeed)
	}

	fromSpeechConfig := InternalGetValueByPath(fromObject, []string{"speechConfig"})
	if fromSpeechConfig != nil {
		InternalSetValueByPath(toObject, []string{"speechConfig"}, fromSpeechConfig)
	}

	fromStopSequences := InternalGetValueByPath(fromObject, []string{"stopSequences"})
	if fromStopSequences != nil {
		InternalSetValueByPath(toObject, []string{"stopSequences"}, fromStopSequences)
	}

	fromTemperature := InternalGetValueByPath(fromObject, []string{"temperature"})
	if fromTemperature != nil {
		InternalSetValueByPath(toObject, []string{"temperature"}, fromTemperature)
	}

	fromThinkingConfig := InternalGetValueByPath(fromObject, []string{"thinkingConfig"})
	if fromThinkingConfig != nil {
		InternalSetValueByPath(toObject, []string{"thinkingConfig"}, fromThinkingConfig)
	}

	fromTopK := InternalGetValueByPath(fromObject, []string{"topK"})
	if fromTopK != nil {
		InternalSetValueByPath(toObject, []string{"topK"}, fromTopK)
	}

	fromTopP := InternalGetValueByPath(fromObject, []string{"topP"})
	if fromTopP != nil {
		InternalSetValueByPath(toObject, []string{"topP"}, fromTopP)
	}

	fromResponseFormat := InternalGetValueByPath(fromObject, []string{"responseFormat"})
	if fromResponseFormat != nil {
		InternalSetValueByPath(toObject, []string{"responseFormat"}, fromResponseFormat)
	}

	return toObject, nil
}

func getTuningJobParametersToMldev(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromName := InternalGetValueByPath(fromObject, []string{"name"})
	if fromName != nil {
		InternalSetValueByPath(toObject, []string{"_url", "name"}, fromName)
	}

	return toObject, nil
}

func getTuningJobParametersToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromName := InternalGetValueByPath(fromObject, []string{"name"})
	if fromName != nil {
		InternalSetValueByPath(toObject, []string{"_url", "name"}, fromName)
	}

	return toObject, nil
}

func listTuningJobsConfigToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromPageSize := InternalGetValueByPath(fromObject, []string{"pageSize"})
	if fromPageSize != nil {
		InternalSetValueByPath(parentObject, []string{"_query", "pageSize"}, fromPageSize)
	}

	fromPageToken := InternalGetValueByPath(fromObject, []string{"pageToken"})
	if fromPageToken != nil {
		InternalSetValueByPath(parentObject, []string{"_query", "pageToken"}, fromPageToken)
	}

	fromFilter := InternalGetValueByPath(fromObject, []string{"filter"})
	if fromFilter != nil {
		InternalSetValueByPath(parentObject, []string{"_query", "filter"}, fromFilter)
	}

	return toObject, nil
}

func listTuningJobsParametersToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromConfig := InternalGetValueByPath(fromObject, []string{"config"})
	if fromConfig != nil {
		_, err = listTuningJobsConfigToVertex(fromConfig.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}
	}

	return toObject, nil
}

func listTuningJobsResponseFromVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromSdkHttpResponse := InternalGetValueByPath(fromObject, []string{"sdkHttpResponse"})
	if fromSdkHttpResponse != nil {
		InternalSetValueByPath(toObject, []string{"sdkHttpResponse"}, fromSdkHttpResponse)
	}

	fromNextPageToken := InternalGetValueByPath(fromObject, []string{"nextPageToken"})
	if fromNextPageToken != nil {
		InternalSetValueByPath(toObject, []string{"nextPageToken"}, fromNextPageToken)
	}

	fromTuningJobs := InternalGetValueByPath(fromObject, []string{"tuningJobs"})
	if fromTuningJobs != nil {
		fromTuningJobs, err = InternalApplyConverterToSliceWithRoot(fromTuningJobs.([]any), tuningJobFromVertex, rootObject)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"tuningJobs"}, fromTuningJobs)
	}

	return toObject, nil
}

func reinforcementTuningExampleToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromContents := InternalGetValueByPath(fromObject, []string{"contents"})
	if fromContents != nil {
		fromContents, err = InternalApplyConverterToSliceWithRoot(fromContents.([]any), contentToVertex, rootObject)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"contents"}, fromContents)
	}

	fromReferences := InternalGetValueByPath(fromObject, []string{"references"})
	if fromReferences != nil {
		InternalSetValueByPath(toObject, []string{"references"}, fromReferences)
	}

	fromSystemInstruction := InternalGetValueByPath(fromObject, []string{"systemInstruction"})
	if fromSystemInstruction != nil {
		fromSystemInstruction, err = contentToVertex(fromSystemInstruction.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"systemInstruction"}, fromSystemInstruction)
	}

	return toObject, nil
}

func tunedModelFromMldev(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromModel := InternalGetValueByPath(fromObject, []string{"name"})
	if fromModel != nil {
		InternalSetValueByPath(toObject, []string{"model"}, fromModel)
	}

	fromEndpoint := InternalGetValueByPath(fromObject, []string{"name"})
	if fromEndpoint != nil {
		InternalSetValueByPath(toObject, []string{"endpoint"}, fromEndpoint)
	}

	return toObject, nil
}

func tuningDatasetToMldev(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)
	if InternalGetValueByPath(fromObject, []string{"gcsUri"}) != nil {
		return nil, fmt.Errorf("gcsUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	if InternalGetValueByPath(fromObject, []string{"vertexDatasetResource"}) != nil {
		return nil, fmt.Errorf("vertexDatasetResource parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")
	}

	fromExamples := InternalGetValueByPath(fromObject, []string{"examples"})
	if fromExamples != nil {
		InternalSetValueByPath(toObject, []string{"examples", "examples"}, fromExamples)
	}

	return toObject, nil
}

func tuningDatasetToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	var discriminatorGcsUri any = InternalGetValueByPath(rootObject, []string{"config", "method"})
	if discriminatorGcsUri == nil {
		discriminatorGcsUri = "SUPERVISED_FINE_TUNING"
	}
	if discriminatorGcsUri.(string) == "SUPERVISED_FINE_TUNING" {
		fromGcsUri := InternalGetValueByPath(fromObject, []string{"gcsUri"})
		if fromGcsUri != nil {
			InternalSetValueByPath(parentObject, []string{"supervisedTuningSpec", "trainingDatasetUri"}, fromGcsUri)
		}
	} else if discriminatorGcsUri.(string) == "PREFERENCE_TUNING" {
		fromGcsUri := InternalGetValueByPath(fromObject, []string{"gcsUri"})
		if fromGcsUri != nil {
			InternalSetValueByPath(parentObject, []string{"preferenceOptimizationSpec", "trainingDatasetUri"}, fromGcsUri)
		}
	} else if discriminatorGcsUri.(string) == "DISTILLATION" {
		fromGcsUri := InternalGetValueByPath(fromObject, []string{"gcsUri"})
		if fromGcsUri != nil {
			InternalSetValueByPath(parentObject, []string{"distillationSpec", "promptDatasetUri"}, fromGcsUri)
		}
	} else if discriminatorGcsUri.(string) == "REINFORCEMENT_TUNING" {
		fromGcsUri := InternalGetValueByPath(fromObject, []string{"gcsUri"})
		if fromGcsUri != nil {
			InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "trainingDatasetUri"}, fromGcsUri)
		}
	}

	var discriminatorVertexDatasetResource any = InternalGetValueByPath(rootObject, []string{"config", "method"})
	if discriminatorVertexDatasetResource == nil {
		discriminatorVertexDatasetResource = "SUPERVISED_FINE_TUNING"
	}
	if discriminatorVertexDatasetResource.(string) == "SUPERVISED_FINE_TUNING" {
		fromVertexDatasetResource := InternalGetValueByPath(fromObject, []string{"vertexDatasetResource"})
		if fromVertexDatasetResource != nil {
			InternalSetValueByPath(parentObject, []string{"supervisedTuningSpec", "trainingDatasetUri"}, fromVertexDatasetResource)
		}
	} else if discriminatorVertexDatasetResource.(string) == "PREFERENCE_TUNING" {
		fromVertexDatasetResource := InternalGetValueByPath(fromObject, []string{"vertexDatasetResource"})
		if fromVertexDatasetResource != nil {
			InternalSetValueByPath(parentObject, []string{"preferenceOptimizationSpec", "trainingDatasetUri"}, fromVertexDatasetResource)
		}
	} else if discriminatorVertexDatasetResource.(string) == "DISTILLATION" {
		fromVertexDatasetResource := InternalGetValueByPath(fromObject, []string{"vertexDatasetResource"})
		if fromVertexDatasetResource != nil {
			InternalSetValueByPath(parentObject, []string{"distillationSpec", "promptDatasetUri"}, fromVertexDatasetResource)
		}
	} else if discriminatorVertexDatasetResource.(string) == "REINFORCEMENT_TUNING" {
		fromVertexDatasetResource := InternalGetValueByPath(fromObject, []string{"vertexDatasetResource"})
		if fromVertexDatasetResource != nil {
			InternalSetValueByPath(parentObject, []string{"reinforcementTuningSpec", "trainingDatasetUri"}, fromVertexDatasetResource)
		}
	}

	if InternalGetValueByPath(fromObject, []string{"examples"}) != nil {
		return nil, fmt.Errorf("examples parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.")
	}

	return toObject, nil
}

func tuningJobFromMldev(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromSdkHttpResponse := InternalGetValueByPath(fromObject, []string{"sdkHttpResponse"})
	if fromSdkHttpResponse != nil {
		InternalSetValueByPath(toObject, []string{"sdkHttpResponse"}, fromSdkHttpResponse)
	}

	fromName := InternalGetValueByPath(fromObject, []string{"name"})
	if fromName != nil {
		InternalSetValueByPath(toObject, []string{"name"}, fromName)
	}

	fromState := InternalGetValueByPath(fromObject, []string{"state"})
	if fromState != nil {
		fromState, err = InternalTTuningJobStatus(fromState)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"state"}, fromState)
	}

	fromCreateTime := InternalGetValueByPath(fromObject, []string{"createTime"})
	if fromCreateTime != nil {
		InternalSetValueByPath(toObject, []string{"createTime"}, fromCreateTime)
	}

	fromStartTime := InternalGetValueByPath(fromObject, []string{"tuningTask", "startTime"})
	if fromStartTime != nil {
		InternalSetValueByPath(toObject, []string{"startTime"}, fromStartTime)
	}

	fromEndTime := InternalGetValueByPath(fromObject, []string{"tuningTask", "completeTime"})
	if fromEndTime != nil {
		InternalSetValueByPath(toObject, []string{"endTime"}, fromEndTime)
	}

	fromUpdateTime := InternalGetValueByPath(fromObject, []string{"updateTime"})
	if fromUpdateTime != nil {
		InternalSetValueByPath(toObject, []string{"updateTime"}, fromUpdateTime)
	}

	fromDescription := InternalGetValueByPath(fromObject, []string{"description"})
	if fromDescription != nil {
		InternalSetValueByPath(toObject, []string{"description"}, fromDescription)
	}

	fromBaseModel := InternalGetValueByPath(fromObject, []string{"baseModel"})
	if fromBaseModel != nil {
		InternalSetValueByPath(toObject, []string{"baseModel"}, fromBaseModel)
	}

	fromTunedModel := InternalGetValueByPath(fromObject, []string{"_self"})
	if fromTunedModel != nil {
		fromTunedModel, err = tunedModelFromMldev(fromTunedModel.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"tunedModel"}, fromTunedModel)
	}

	return toObject, nil
}

func tuningJobFromVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromSdkHttpResponse := InternalGetValueByPath(fromObject, []string{"sdkHttpResponse"})
	if fromSdkHttpResponse != nil {
		InternalSetValueByPath(toObject, []string{"sdkHttpResponse"}, fromSdkHttpResponse)
	}

	fromName := InternalGetValueByPath(fromObject, []string{"name"})
	if fromName != nil {
		InternalSetValueByPath(toObject, []string{"name"}, fromName)
	}

	fromState := InternalGetValueByPath(fromObject, []string{"state"})
	if fromState != nil {
		fromState, err = InternalTTuningJobStatus(fromState)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"state"}, fromState)
	}

	fromCreateTime := InternalGetValueByPath(fromObject, []string{"createTime"})
	if fromCreateTime != nil {
		InternalSetValueByPath(toObject, []string{"createTime"}, fromCreateTime)
	}

	fromStartTime := InternalGetValueByPath(fromObject, []string{"startTime"})
	if fromStartTime != nil {
		InternalSetValueByPath(toObject, []string{"startTime"}, fromStartTime)
	}

	fromEndTime := InternalGetValueByPath(fromObject, []string{"endTime"})
	if fromEndTime != nil {
		InternalSetValueByPath(toObject, []string{"endTime"}, fromEndTime)
	}

	fromUpdateTime := InternalGetValueByPath(fromObject, []string{"updateTime"})
	if fromUpdateTime != nil {
		InternalSetValueByPath(toObject, []string{"updateTime"}, fromUpdateTime)
	}

	fromError := InternalGetValueByPath(fromObject, []string{"error"})
	if fromError != nil {
		InternalSetValueByPath(toObject, []string{"error"}, fromError)
	}

	fromDescription := InternalGetValueByPath(fromObject, []string{"description"})
	if fromDescription != nil {
		InternalSetValueByPath(toObject, []string{"description"}, fromDescription)
	}

	fromBaseModel := InternalGetValueByPath(fromObject, []string{"baseModel"})
	if fromBaseModel != nil {
		InternalSetValueByPath(toObject, []string{"baseModel"}, fromBaseModel)
	}

	fromTunedModel := InternalGetValueByPath(fromObject, []string{"tunedModel"})
	if fromTunedModel != nil {
		InternalSetValueByPath(toObject, []string{"tunedModel"}, fromTunedModel)
	}

	fromPreTunedModel := InternalGetValueByPath(fromObject, []string{"preTunedModel"})
	if fromPreTunedModel != nil {
		InternalSetValueByPath(toObject, []string{"preTunedModel"}, fromPreTunedModel)
	}

	fromSupervisedTuningSpec := InternalGetValueByPath(fromObject, []string{"supervisedTuningSpec"})
	if fromSupervisedTuningSpec != nil {
		InternalSetValueByPath(toObject, []string{"supervisedTuningSpec"}, fromSupervisedTuningSpec)
	}

	fromPreferenceOptimizationSpec := InternalGetValueByPath(fromObject, []string{"preferenceOptimizationSpec"})
	if fromPreferenceOptimizationSpec != nil {
		InternalSetValueByPath(toObject, []string{"preferenceOptimizationSpec"}, fromPreferenceOptimizationSpec)
	}

	fromDistillationSpec := InternalGetValueByPath(fromObject, []string{"distillationSpec"})
	if fromDistillationSpec != nil {
		fromDistillationSpec, err = distillationSpecFromVertex(fromDistillationSpec.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"distillationSpec"}, fromDistillationSpec)
	}

	fromReinforcementTuningSpec := InternalGetValueByPath(fromObject, []string{"reinforcementTuningSpec"})
	if fromReinforcementTuningSpec != nil {
		InternalSetValueByPath(toObject, []string{"reinforcementTuningSpec"}, fromReinforcementTuningSpec)
	}

	fromTuningDataStats := InternalGetValueByPath(fromObject, []string{"tuningDataStats"})
	if fromTuningDataStats != nil {
		InternalSetValueByPath(toObject, []string{"tuningDataStats"}, fromTuningDataStats)
	}

	fromEncryptionSpec := InternalGetValueByPath(fromObject, []string{"encryptionSpec"})
	if fromEncryptionSpec != nil {
		InternalSetValueByPath(toObject, []string{"encryptionSpec"}, fromEncryptionSpec)
	}

	fromPartnerModelTuningSpec := InternalGetValueByPath(fromObject, []string{"partnerModelTuningSpec"})
	if fromPartnerModelTuningSpec != nil {
		InternalSetValueByPath(toObject, []string{"partnerModelTuningSpec"}, fromPartnerModelTuningSpec)
	}

	fromCustomBaseModel := InternalGetValueByPath(fromObject, []string{"customBaseModel"})
	if fromCustomBaseModel != nil {
		InternalSetValueByPath(toObject, []string{"customBaseModel"}, fromCustomBaseModel)
	}

	fromEvaluateDatasetRuns := InternalGetValueByPath(fromObject, []string{"evaluateDatasetRuns"})
	if fromEvaluateDatasetRuns != nil {
		InternalSetValueByPath(toObject, []string{"evaluateDatasetRuns"}, fromEvaluateDatasetRuns)
	}

	fromExperiment := InternalGetValueByPath(fromObject, []string{"experiment"})
	if fromExperiment != nil {
		InternalSetValueByPath(toObject, []string{"experiment"}, fromExperiment)
	}

	fromFullFineTuningSpec := InternalGetValueByPath(fromObject, []string{"fullFineTuningSpec"})
	if fromFullFineTuningSpec != nil {
		InternalSetValueByPath(toObject, []string{"fullFineTuningSpec"}, fromFullFineTuningSpec)
	}

	fromLabels := InternalGetValueByPath(fromObject, []string{"labels"})
	if fromLabels != nil {
		InternalSetValueByPath(toObject, []string{"labels"}, fromLabels)
	}

	fromOutputUri := InternalGetValueByPath(fromObject, []string{"outputUri"})
	if fromOutputUri != nil {
		InternalSetValueByPath(toObject, []string{"outputUri"}, fromOutputUri)
	}

	fromPipelineJob := InternalGetValueByPath(fromObject, []string{"pipelineJob"})
	if fromPipelineJob != nil {
		InternalSetValueByPath(toObject, []string{"pipelineJob"}, fromPipelineJob)
	}

	fromServiceAccount := InternalGetValueByPath(fromObject, []string{"serviceAccount"})
	if fromServiceAccount != nil {
		InternalSetValueByPath(toObject, []string{"serviceAccount"}, fromServiceAccount)
	}

	fromTunedModelDisplayName := InternalGetValueByPath(fromObject, []string{"tunedModelDisplayName"})
	if fromTunedModelDisplayName != nil {
		InternalSetValueByPath(toObject, []string{"tunedModelDisplayName"}, fromTunedModelDisplayName)
	}

	fromTuningJobState := InternalGetValueByPath(fromObject, []string{"tuningJobState"})
	if fromTuningJobState != nil {
		InternalSetValueByPath(toObject, []string{"tuningJobState"}, fromTuningJobState)
	}

	fromVeoTuningSpec := InternalGetValueByPath(fromObject, []string{"veoTuningSpec"})
	if fromVeoTuningSpec != nil {
		InternalSetValueByPath(toObject, []string{"veoTuningSpec"}, fromVeoTuningSpec)
	}

	fromTuningJobMetadata := InternalGetValueByPath(fromObject, []string{"tuningJobMetadata"})
	if fromTuningJobMetadata != nil {
		InternalSetValueByPath(toObject, []string{"tuningJobMetadata"}, fromTuningJobMetadata)
	}

	fromVeoLoraTuningSpec := InternalGetValueByPath(fromObject, []string{"veoLoraTuningSpec"})
	if fromVeoLoraTuningSpec != nil {
		InternalSetValueByPath(toObject, []string{"veoLoraTuningSpec"}, fromVeoLoraTuningSpec)
	}

	fromDistillationSamplingSpec := InternalGetValueByPath(fromObject, []string{"distillationSamplingSpec"})
	if fromDistillationSamplingSpec != nil {
		fromDistillationSamplingSpec, err = distillationSamplingSpecFromVertex(fromDistillationSamplingSpec.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"distillationSamplingSpec"}, fromDistillationSamplingSpec)
	}

	return toObject, nil
}

func tuningOperationFromMldev(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromSdkHttpResponse := InternalGetValueByPath(fromObject, []string{"sdkHttpResponse"})
	if fromSdkHttpResponse != nil {
		InternalSetValueByPath(toObject, []string{"sdkHttpResponse"}, fromSdkHttpResponse)
	}

	fromName := InternalGetValueByPath(fromObject, []string{"name"})
	if fromName != nil {
		InternalSetValueByPath(toObject, []string{"name"}, fromName)
	}

	fromMetadata := InternalGetValueByPath(fromObject, []string{"metadata"})
	if fromMetadata != nil {
		InternalSetValueByPath(toObject, []string{"metadata"}, fromMetadata)
	}

	fromDone := InternalGetValueByPath(fromObject, []string{"done"})
	if fromDone != nil {
		InternalSetValueByPath(toObject, []string{"done"}, fromDone)
	}

	fromError := InternalGetValueByPath(fromObject, []string{"error"})
	if fromError != nil {
		InternalSetValueByPath(toObject, []string{"error"}, fromError)
	}

	return toObject, nil
}

func tuningValidationDatasetToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromGcsUri := InternalGetValueByPath(fromObject, []string{"gcsUri"})
	if fromGcsUri != nil {
		InternalSetValueByPath(toObject, []string{"validationDatasetUri"}, fromGcsUri)
	}

	fromVertexDatasetResource := InternalGetValueByPath(fromObject, []string{"vertexDatasetResource"})
	if fromVertexDatasetResource != nil {
		InternalSetValueByPath(toObject, []string{"validationDatasetUri"}, fromVertexDatasetResource)
	}

	return toObject, nil
}

func validateRewardParametersToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromParent := InternalGetValueByPath(fromObject, []string{"parent"})
	if fromParent != nil {
		InternalSetValueByPath(toObject, []string{"_url", "parent"}, fromParent)
	}

	fromSampleResponse := InternalGetValueByPath(fromObject, []string{"sampleResponse"})
	if fromSampleResponse != nil {
		fromSampleResponse, err = contentToVertex(fromSampleResponse.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"sampleResponse"}, fromSampleResponse)
	}

	fromExample := InternalGetValueByPath(fromObject, []string{"example"})
	if fromExample != nil {
		fromExample, err = reinforcementTuningExampleToVertex(fromExample.(map[string]any), toObject, rootObject)
		if err != nil {
			return nil, err
		}

		InternalSetValueByPath(toObject, []string{"example"}, fromExample)
	}

	fromSingleRewardConfig := InternalGetValueByPath(fromObject, []string{"singleRewardConfig"})
	if fromSingleRewardConfig != nil {
		InternalSetValueByPath(toObject, []string{"singleRewardConfig"}, fromSingleRewardConfig)
	}

	fromCompositeRewardConfig := InternalGetValueByPath(fromObject, []string{"compositeRewardConfig"})
	if fromCompositeRewardConfig != nil {
		InternalSetValueByPath(toObject, []string{"compositeRewardConfig"}, fromCompositeRewardConfig)
	}

	return toObject, nil
}

func validateRewardResponseFromVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) {
	toObject = make(map[string]any)

	fromSdkHttpResponse := InternalGetValueByPath(fromObject, []string{"sdkHttpResponse"})
	if fromSdkHttpResponse != nil {
		InternalSetValueByPath(toObject, []string{"sdkHttpResponse"}, fromSdkHttpResponse)
	}

	fromOverallReward := InternalGetValueByPath(fromObject, []string{"overallReward"})
	if fromOverallReward != nil {
		InternalSetValueByPath(toObject, []string{"overallReward"}, fromOverallReward)
	}

	fromError := InternalGetValueByPath(fromObject, []string{"error"})
	if fromError != nil {
		InternalSetValueByPath(toObject, []string{"error"}, fromError)
	}

	fromRewardInfoDetails := InternalGetValueByPath(fromObject, []string{"rewardInfoDetails"})
	if fromRewardInfoDetails != nil {
		InternalSetValueByPath(toObject, []string{"rewardInfoDetails"}, fromRewardInfoDetails)
	}

	return toObject, nil
}

type Tunings struct {
	apiClient *InternalAPIClient
}

func (m Tunings) get(ctx context.Context, name string, config *GetTuningJobConfig) (*TuningJob, error) {
	parameterMap := make(map[string]any)

	kwargs := map[string]any{"name": name, "config": config}
	InternalDeepMarshal(kwargs, &parameterMap)

	var httpOptions *HTTPOptions
	if config == nil || config.HTTPOptions == nil {
		httpOptions = &HTTPOptions{}
	} else {
		httpOptions = config.HTTPOptions
	}
	if httpOptions.Headers == nil {
		httpOptions.Headers = http.Header{}
	}
	var response = new(TuningJob)
	var responseMap map[string]any
	var fromConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	var toConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	if m.apiClient.ClientConfig().Backend == BackendVertexAI {
		toConverter = getTuningJobParametersToVertex
		fromConverter = tuningJobFromVertex
	} else {
		toConverter = getTuningJobParametersToMldev
		fromConverter = tuningJobFromMldev
	}

	body, err := toConverter(parameterMap, nil, parameterMap)
	if err != nil {
		return nil, err
	}

	var path string
	var urlParams map[string]any
	if _, ok := body["_url"]; ok {
		urlParams = body["_url"].(map[string]any)
		delete(body, "_url")
	}
	path, err = InternalFormatMap("{name}", urlParams)
	if err != nil {
		return nil, fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err)
	}
	if _, ok := body["_query"]; ok {
		query, err := InternalCreateURLQuery(body["_query"].(map[string]any))
		if err != nil {
			return nil, err
		}
		path += "?" + query
		delete(body, "_query")
	}
	responseMap, err = sendRequest(ctx, m.apiClient, path, http.MethodGet, body, httpOptions)
	if err != nil {
		return nil, err
	}
	if fromConverter != nil {
		responseMap, err = fromConverter(responseMap, nil, parameterMap)
	}
	if err != nil {
		return nil, err
	}
	err = InternalMapToStruct(responseMap, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}

func (m Tunings) list(ctx context.Context, config *ListTuningJobsConfig) (*ListTuningJobsResponse, error) {
	parameterMap := make(map[string]any)

	kwargs := map[string]any{"config": config}
	InternalDeepMarshal(kwargs, &parameterMap)

	var httpOptions *HTTPOptions
	if config == nil || config.HTTPOptions == nil {
		httpOptions = &HTTPOptions{}
	} else {
		httpOptions = config.HTTPOptions
	}
	if httpOptions.Headers == nil {
		httpOptions.Headers = http.Header{}
	}
	var response = new(ListTuningJobsResponse)
	var responseMap map[string]any
	var fromConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	var toConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	if m.apiClient.ClientConfig().Backend == BackendVertexAI {
		toConverter = listTuningJobsParametersToVertex
		fromConverter = listTuningJobsResponseFromVertex
	} else {

		return nil, fmt.Errorf("method List is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode. You can choose to use Gemini Enterprise Agent Platform by setting ClientConfig.Backend to BackendEnterprise.")

	}

	body, err := toConverter(parameterMap, nil, parameterMap)
	if err != nil {
		return nil, err
	}

	var path string
	var urlParams map[string]any
	if _, ok := body["_url"]; ok {
		urlParams = body["_url"].(map[string]any)
		delete(body, "_url")
	}
	if m.apiClient.ClientConfig().Backend == BackendVertexAI {
		path, err = InternalFormatMap("tuningJobs", urlParams)
	} else {
		path, err = InternalFormatMap("None", urlParams)
	}
	if err != nil {
		return nil, fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err)
	}
	if _, ok := body["_query"]; ok {
		query, err := InternalCreateURLQuery(body["_query"].(map[string]any))
		if err != nil {
			return nil, err
		}
		path += "?" + query
		delete(body, "_query")
	}
	responseMap, err = sendRequest(ctx, m.apiClient, path, http.MethodGet, body, httpOptions)
	if err != nil {
		return nil, err
	}
	if fromConverter != nil {
		responseMap, err = fromConverter(responseMap, nil, parameterMap)
	}
	if err != nil {
		return nil, err
	}
	err = InternalMapToStruct(responseMap, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}

// Cancel cancels a tuning job resource.
func (m Tunings) Cancel(ctx context.Context, name string, config *CancelTuningJobConfig) (*CancelTuningJobResponse, error) {
	parameterMap := make(map[string]any)

	kwargs := map[string]any{"name": name, "config": config}
	InternalDeepMarshal(kwargs, &parameterMap)

	var httpOptions *HTTPOptions
	if config == nil || config.HTTPOptions == nil {
		httpOptions = &HTTPOptions{}
	} else {
		httpOptions = config.HTTPOptions
	}
	if httpOptions.Headers == nil {
		httpOptions.Headers = http.Header{}
	}
	var response = new(CancelTuningJobResponse)
	var responseMap map[string]any
	var fromConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	var toConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	if m.apiClient.ClientConfig().Backend == BackendVertexAI {
		toConverter = cancelTuningJobParametersToVertex
		fromConverter = cancelTuningJobResponseFromVertex
	} else {
		toConverter = cancelTuningJobParametersToMldev
		fromConverter = cancelTuningJobResponseFromMldev
	}

	body, err := toConverter(parameterMap, nil, parameterMap)
	if err != nil {
		return nil, err
	}

	var path string
	var urlParams map[string]any
	if _, ok := body["_url"]; ok {
		urlParams = body["_url"].(map[string]any)
		delete(body, "_url")
	}
	path, err = InternalFormatMap("{name}:cancel", urlParams)
	if err != nil {
		return nil, fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err)
	}
	if _, ok := body["_query"]; ok {
		query, err := InternalCreateURLQuery(body["_query"].(map[string]any))
		if err != nil {
			return nil, err
		}
		path += "?" + query
		delete(body, "_query")
	}
	responseMap, err = sendRequest(ctx, m.apiClient, path, http.MethodPost, body, httpOptions)
	if err != nil {
		return nil, err
	}
	if fromConverter != nil {
		responseMap, err = fromConverter(responseMap, nil, parameterMap)
	}
	if err != nil {
		return nil, err
	}
	err = InternalMapToStruct(responseMap, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}

func (m Tunings) tune(ctx context.Context, baseModel *string, preTunedModel *PreTunedModel, trainingDataset *TuningDataset, config *CreateTuningJobConfig) (*TuningJob, error) {
	parameterMap := make(map[string]any)

	kwargs := map[string]any{"baseModel": baseModel, "preTunedModel": preTunedModel, "trainingDataset": trainingDataset, "config": config}
	InternalDeepMarshal(kwargs, &parameterMap)

	var httpOptions *HTTPOptions
	if config == nil || config.HTTPOptions == nil {
		httpOptions = &HTTPOptions{}
	} else {
		httpOptions = config.HTTPOptions
	}
	if httpOptions.Headers == nil {
		httpOptions.Headers = http.Header{}
	}
	var response = new(TuningJob)
	var responseMap map[string]any
	var fromConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	var toConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	if m.apiClient.ClientConfig().Backend == BackendVertexAI {
		toConverter = createTuningJobParametersPrivateToVertex
		fromConverter = tuningJobFromVertex
	} else {

		return nil, fmt.Errorf("method Tune is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode. You can choose to use Gemini Enterprise Agent Platform by setting ClientConfig.Backend to BackendEnterprise.")

	}

	body, err := toConverter(parameterMap, nil, parameterMap)
	if err != nil {
		return nil, err
	}

	var path string
	var urlParams map[string]any
	if _, ok := body["_url"]; ok {
		urlParams = body["_url"].(map[string]any)
		delete(body, "_url")
	}
	if m.apiClient.ClientConfig().Backend == BackendVertexAI {
		path, err = InternalFormatMap("tuningJobs", urlParams)
	} else {
		path, err = InternalFormatMap("None", urlParams)
	}
	if err != nil {
		return nil, fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err)
	}
	if _, ok := body["_query"]; ok {
		query, err := InternalCreateURLQuery(body["_query"].(map[string]any))
		if err != nil {
			return nil, err
		}
		path += "?" + query
		delete(body, "_query")
	}
	responseMap, err = sendRequest(ctx, m.apiClient, path, http.MethodPost, body, httpOptions)
	if err != nil {
		return nil, err
	}
	if fromConverter != nil {
		responseMap, err = fromConverter(responseMap, nil, parameterMap)
	}
	if err != nil {
		return nil, err
	}
	err = InternalMapToStruct(responseMap, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}

func (m Tunings) tuneMldev(ctx context.Context, baseModel *string, preTunedModel *PreTunedModel, trainingDataset *TuningDataset, config *CreateTuningJobConfig) (*TuningOperation, error) {
	parameterMap := make(map[string]any)

	kwargs := map[string]any{"baseModel": baseModel, "preTunedModel": preTunedModel, "trainingDataset": trainingDataset, "config": config}
	InternalDeepMarshal(kwargs, &parameterMap)

	var httpOptions *HTTPOptions
	if config == nil || config.HTTPOptions == nil {
		httpOptions = &HTTPOptions{}
	} else {
		httpOptions = config.HTTPOptions
	}
	if httpOptions.Headers == nil {
		httpOptions.Headers = http.Header{}
	}
	var response = new(TuningOperation)
	var responseMap map[string]any
	var fromConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	var toConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	if m.apiClient.ClientConfig().Backend == BackendVertexAI {

		return nil, fmt.Errorf("method TuneMldev is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode. You can choose to use Gemini Developer client by setting ClientConfig.Backend to BackendGeminiAPI.")

	} else {
		toConverter = createTuningJobParametersPrivateToMldev
		fromConverter = tuningOperationFromMldev
	}

	body, err := toConverter(parameterMap, nil, parameterMap)
	if err != nil {
		return nil, err
	}

	var path string
	var urlParams map[string]any
	if _, ok := body["_url"]; ok {
		urlParams = body["_url"].(map[string]any)
		delete(body, "_url")
	}
	if m.apiClient.ClientConfig().Backend == BackendVertexAI {
		path, err = InternalFormatMap("None", urlParams)
	} else {
		path, err = InternalFormatMap("tunedModels", urlParams)
	}
	if err != nil {
		return nil, fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err)
	}
	if _, ok := body["_query"]; ok {
		query, err := InternalCreateURLQuery(body["_query"].(map[string]any))
		if err != nil {
			return nil, err
		}
		path += "?" + query
		delete(body, "_query")
	}
	responseMap, err = sendRequest(ctx, m.apiClient, path, http.MethodPost, body, httpOptions)
	if err != nil {
		return nil, err
	}
	if fromConverter != nil {
		responseMap, err = fromConverter(responseMap, nil, parameterMap)
	}
	if err != nil {
		return nil, err
	}
	err = InternalMapToStruct(responseMap, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}

func (m Tunings) ValidateReward(ctx context.Context, parent string, sampleResponse *Content, example *ReinforcementTuningExample, singleRewardConfig *SingleReinforcementTuningRewardConfig, compositeRewardConfig *CompositeReinforcementTuningRewardConfig, config *ValidateRewardConfig) (*ValidateRewardResponse, error) {
	parameterMap := make(map[string]any)

	kwargs := map[string]any{"parent": parent, "sampleResponse": sampleResponse, "example": example, "singleRewardConfig": singleRewardConfig, "compositeRewardConfig": compositeRewardConfig, "config": config}
	InternalDeepMarshal(kwargs, &parameterMap)

	var httpOptions *HTTPOptions
	if config == nil || config.HTTPOptions == nil {
		httpOptions = &HTTPOptions{}
	} else {
		httpOptions = config.HTTPOptions
	}
	if httpOptions.Headers == nil {
		httpOptions.Headers = http.Header{}
	}
	var response = new(ValidateRewardResponse)
	var responseMap map[string]any
	var fromConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	var toConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error)
	if m.apiClient.ClientConfig().Backend == BackendVertexAI {
		toConverter = validateRewardParametersToVertex
		fromConverter = validateRewardResponseFromVertex
	} else {

		return nil, fmt.Errorf("method ValidateReward is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode. You can choose to use Gemini Enterprise Agent Platform by setting ClientConfig.Backend to BackendEnterprise.")

	}

	body, err := toConverter(parameterMap, nil, parameterMap)
	if err != nil {
		return nil, err
	}

	var path string
	var urlParams map[string]any
	if _, ok := body["_url"]; ok {
		urlParams = body["_url"].(map[string]any)
		delete(body, "_url")
	}
	if m.apiClient.ClientConfig().Backend == BackendVertexAI {
		path, err = InternalFormatMap("{parent}/tuningJobs:validateReinforcementTuningReward", urlParams)
	} else {
		path, err = InternalFormatMap("None", urlParams)
	}
	if err != nil {
		return nil, fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err)
	}
	if _, ok := body["_query"]; ok {
		query, err := InternalCreateURLQuery(body["_query"].(map[string]any))
		if err != nil {
			return nil, err
		}
		path += "?" + query
		delete(body, "_query")
	}
	responseMap, err = sendRequest(ctx, m.apiClient, path, http.MethodPost, body, httpOptions)
	if err != nil {
		return nil, err
	}
	if fromConverter != nil {
		responseMap, err = fromConverter(responseMap, nil, parameterMap)
	}
	if err != nil {
		return nil, err
	}
	err = InternalMapToStruct(responseMap, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}

// List retrieves a paginated list of tuning_jobs resources.
func (m Tunings) List(ctx context.Context, config *ListTuningJobsConfig) (Page[TuningJob], error) {
	listFunc := func(ctx context.Context, config map[string]any) ([]*TuningJob, string, *HTTPResponse, error) {
		var c ListTuningJobsConfig
		if err := InternalMapToStruct(config, &c); err != nil {
			return nil, "", nil, err
		}
		resp, err := m.list(ctx, &c)
		if err != nil {
			return nil, "", nil, err
		}
		return resp.TuningJobs, resp.NextPageToken, resp.SDKHTTPResponse, nil
	}
	c := make(map[string]any)
	InternalDeepMarshal(config, &c)
	return newPage(ctx, "tuningJobs", c, listFunc)
}

// All retrieves all tuning_jobs resources.
//
// This method handles pagination internally, making multiple API calls as needed
// to fetch all entries. It returns an iterator that yields each "tuningJobs"
// entry one by one. You do not need to manage pagination
// tokens or make multiple calls to retrieve all data.
func (m Tunings) All(ctx context.Context) iter.Seq2[*TuningJob, error] {
	listFunc := func(ctx context.Context, config map[string]any) ([]*TuningJob, string, *HTTPResponse, error) {
		var c ListTuningJobsConfig
		if err := InternalMapToStruct(config, &c); err != nil {
			return nil, "", nil, err
		}
		resp, err := m.list(ctx, &c)
		if err != nil {
			return nil, "", nil, err
		}
		return resp.TuningJobs, resp.NextPageToken, resp.SDKHTTPResponse, nil
	}
	p, err := newPage(ctx, "tuningJobs", map[string]any{}, listFunc)
	if err != nil {
		return yieldErrorAndEndIterator[TuningJob](err)
	}
	return p.all(ctx)
}

var experimentalWarningTuningsCreateOperation sync.Once

// Tune creates a tuning job resource.
func (t Tunings) Tune(ctx context.Context, baseModel string, trainingDataset *TuningDataset, config *CreateTuningJobConfig) (*TuningJob, error) {
	experimentalWarningTuningsCreateOperation.Do(func() {
		log.Println("The SDK's tuning implementation is experimental, and may change in future versions.")
	})
	if t.apiClient.clientConfig.Backend == BackendVertexAI {
		if strings.HasPrefix(baseModel, "projects/") {
			preTunedModel := &PreTunedModel{TunedModelName: baseModel}
			if config != nil && config.PreTunedModelCheckpointID != "" {
				preTunedModel.CheckpointID = config.PreTunedModelCheckpointID
			}
			return t.tune(ctx, nil, preTunedModel, trainingDataset, config)
		} else {
			return t.tune(ctx, &baseModel, nil, trainingDataset, config)
		}
	} else {
		operation, err := t.tuneMldev(ctx, &baseModel, nil, trainingDataset, config)
		if err != nil {
			return nil, err
		}
		if operation == nil {
			return nil, fmt.Errorf("operation is nil")
		}
		if operation.Metadata != nil {
			if tunedModel, ok := operation.Metadata["tunedModel"].(string); ok {
				return &TuningJob{
					Name:  tunedModel,
					State: JobStateQueued,
				}, nil
			}
		}

		if operation.Name == "" {
			return nil, fmt.Errorf("operation name is required")
		}

		parts := strings.Split(operation.Name, "/operations/")
		tunedModelName := parts[0]
		return &TuningJob{
			Name:  tunedModelName,
			State: JobStateQueued,
		}, nil
	}
}

// Get retrieves a tuning job resource.
func (t Tunings) Get(ctx context.Context, name string, config *GetTuningJobConfig) (*TuningJob, error) {
	return t.get(ctx, name, config)
}
