// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.machinelearning.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.machinelearning.models.BlockedTransformers;
import com.azure.resourcemanager.machinelearning.models.FeaturizationMode;
import com.azure.resourcemanager.machinelearning.models.InputDeliveryMode;
import com.azure.resourcemanager.machinelearning.models.LogVerbosity;
import com.azure.resourcemanager.machinelearning.models.MLTableJobInput;
import com.azure.resourcemanager.machinelearning.models.NCrossValidations;
import com.azure.resourcemanager.machinelearning.models.Regression;
import com.azure.resourcemanager.machinelearning.models.RegressionModels;
import com.azure.resourcemanager.machinelearning.models.RegressionPrimaryMetrics;
import com.azure.resourcemanager.machinelearning.models.RegressionTrainingSettings;
import com.azure.resourcemanager.machinelearning.models.StackEnsembleSettings;
import com.azure.resourcemanager.machinelearning.models.StackMetaLearnerType;
import com.azure.resourcemanager.machinelearning.models.TableVerticalFeaturizationSettings;
import com.azure.resourcemanager.machinelearning.models.TableVerticalLimitSettings;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class RegressionTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        Regression model =
            BinaryData
                .fromString(
                    "{\"taskType\":\"Regression\",\"primaryMetric\":\"NormalizedRootMeanSquaredError\",\"trainingSettings\":{\"allowedTrainingAlgorithms\":[\"ElasticNet\"],\"blockedTrainingAlgorithms\":[\"ExtremeRandomTrees\",\"ElasticNet\"],\"enableDnnTraining\":false,\"enableModelExplainability\":false,\"enableOnnxCompatibleModels\":false,\"enableStackEnsemble\":true,\"enableVoteEnsemble\":false,\"ensembleModelDownloadTimeout\":\"PT84H43M30S\",\"stackEnsembleSettings\":{\"stackMetaLearnerKWargs\":\"datavsi\",\"stackMetaLearnerTrainPercentage\":29.842412252567886,\"stackMetaLearnerType\":\"LightGBMRegressor\"}},\"cvSplitColumnNames\":[\"zydisnuep\",\"wyj\",\"nldpxottd\"],\"featurizationSettings\":{\"blockedTransformers\":[\"CountVectorizer\",\"WoETargetEncoder\"],\"columnNameAndTypes\":{\"vcjwqwoqsratj\":\"zjihweebiphr\",\"jhfrzgdkkagv\":\"dhzybsp\"},\"enableDnnFeaturization\":true,\"mode\":\"Custom\",\"transformerParams\":{\"mo\":[]},\"datasetLanguage\":\"mzhwilzzhni\"},\"limitSettings\":{\"enableEarlyTermination\":true,\"exitScore\":3.9502204468192637,\"maxConcurrentTrials\":2133816848,\"maxCoresPerTrial\":444992966,\"maxTrials\":1238035913,\"timeout\":\"PT160H46M45S\",\"trialTimeout\":\"PT11H57M31S\"},\"nCrossValidations\":{\"mode\":\"NCrossValidations\"},\"testData\":{\"jobInputType\":\"mltable\",\"mode\":\"EvalDownload\",\"uri\":\"bkut\",\"description\":\"mltwjfluxynbpvzl\"},\"testDataSize\":9.59052197916832,\"validationData\":{\"jobInputType\":\"mltable\",\"mode\":\"EvalMount\",\"uri\":\"njc\",\"description\":\"mocgjshg\"},\"validationDataSize\":1.3885888922809064,\"weightColumnName\":\"wvixq\",\"logVerbosity\":\"Error\",\"targetColumnName\":\"jkyb\",\"trainingData\":{\"jobInputType\":\"mltable\",\"mode\":\"ReadWriteMount\",\"uri\":\"clrvtzqnrbctbh\",\"description\":\"hxpcvrdnyeita\"}}")
                .toObject(Regression.class);
        Assertions.assertEquals(LogVerbosity.ERROR, model.logVerbosity());
        Assertions.assertEquals("jkyb", model.targetColumnName());
        Assertions.assertEquals("hxpcvrdnyeita", model.trainingData().description());
        Assertions.assertEquals(InputDeliveryMode.READ_WRITE_MOUNT, model.trainingData().mode());
        Assertions.assertEquals("clrvtzqnrbctbh", model.trainingData().uri());
        Assertions.assertEquals(RegressionPrimaryMetrics.NORMALIZED_ROOT_MEAN_SQUARED_ERROR, model.primaryMetric());
        Assertions.assertEquals(false, model.trainingSettings().enableDnnTraining());
        Assertions.assertEquals(false, model.trainingSettings().enableModelExplainability());
        Assertions.assertEquals(false, model.trainingSettings().enableOnnxCompatibleModels());
        Assertions.assertEquals(true, model.trainingSettings().enableStackEnsemble());
        Assertions.assertEquals(false, model.trainingSettings().enableVoteEnsemble());
        Assertions.assertEquals(Duration.parse("PT84H43M30S"), model.trainingSettings().ensembleModelDownloadTimeout());
        Assertions
            .assertEquals(
                29.842412252567886D,
                model.trainingSettings().stackEnsembleSettings().stackMetaLearnerTrainPercentage());
        Assertions
            .assertEquals(
                StackMetaLearnerType.LIGHT_GBMREGRESSOR,
                model.trainingSettings().stackEnsembleSettings().stackMetaLearnerType());
        Assertions
            .assertEquals(RegressionModels.ELASTIC_NET, model.trainingSettings().allowedTrainingAlgorithms().get(0));
        Assertions
            .assertEquals(
                RegressionModels.EXTREME_RANDOM_TREES, model.trainingSettings().blockedTrainingAlgorithms().get(0));
        Assertions.assertEquals("zydisnuep", model.cvSplitColumnNames().get(0));
        Assertions.assertEquals("mzhwilzzhni", model.featurizationSettings().datasetLanguage());
        Assertions
            .assertEquals(
                BlockedTransformers.COUNT_VECTORIZER, model.featurizationSettings().blockedTransformers().get(0));
        Assertions
            .assertEquals("zjihweebiphr", model.featurizationSettings().columnNameAndTypes().get("vcjwqwoqsratj"));
        Assertions.assertEquals(true, model.featurizationSettings().enableDnnFeaturization());
        Assertions.assertEquals(FeaturizationMode.CUSTOM, model.featurizationSettings().mode());
        Assertions.assertEquals(true, model.limitSettings().enableEarlyTermination());
        Assertions.assertEquals(3.9502204468192637D, model.limitSettings().exitScore());
        Assertions.assertEquals(2133816848, model.limitSettings().maxConcurrentTrials());
        Assertions.assertEquals(444992966, model.limitSettings().maxCoresPerTrial());
        Assertions.assertEquals(1238035913, model.limitSettings().maxTrials());
        Assertions.assertEquals(Duration.parse("PT160H46M45S"), model.limitSettings().timeout());
        Assertions.assertEquals(Duration.parse("PT11H57M31S"), model.limitSettings().trialTimeout());
        Assertions.assertEquals("mltwjfluxynbpvzl", model.testData().description());
        Assertions.assertEquals(InputDeliveryMode.EVAL_DOWNLOAD, model.testData().mode());
        Assertions.assertEquals("bkut", model.testData().uri());
        Assertions.assertEquals(9.59052197916832D, model.testDataSize());
        Assertions.assertEquals("mocgjshg", model.validationData().description());
        Assertions.assertEquals(InputDeliveryMode.EVAL_MOUNT, model.validationData().mode());
        Assertions.assertEquals("njc", model.validationData().uri());
        Assertions.assertEquals(1.3885888922809064D, model.validationDataSize());
        Assertions.assertEquals("wvixq", model.weightColumnName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        Regression model =
            new Regression()
                .withLogVerbosity(LogVerbosity.ERROR)
                .withTargetColumnName("jkyb")
                .withTrainingData(
                    new MLTableJobInput()
                        .withDescription("hxpcvrdnyeita")
                        .withMode(InputDeliveryMode.READ_WRITE_MOUNT)
                        .withUri("clrvtzqnrbctbh"))
                .withPrimaryMetric(RegressionPrimaryMetrics.NORMALIZED_ROOT_MEAN_SQUARED_ERROR)
                .withTrainingSettings(
                    new RegressionTrainingSettings()
                        .withEnableDnnTraining(false)
                        .withEnableModelExplainability(false)
                        .withEnableOnnxCompatibleModels(false)
                        .withEnableStackEnsemble(true)
                        .withEnableVoteEnsemble(false)
                        .withEnsembleModelDownloadTimeout(Duration.parse("PT84H43M30S"))
                        .withStackEnsembleSettings(
                            new StackEnsembleSettings()
                                .withStackMetaLearnerKWargs("datavsi")
                                .withStackMetaLearnerTrainPercentage(29.842412252567886D)
                                .withStackMetaLearnerType(StackMetaLearnerType.LIGHT_GBMREGRESSOR))
                        .withAllowedTrainingAlgorithms(Arrays.asList(RegressionModels.ELASTIC_NET))
                        .withBlockedTrainingAlgorithms(
                            Arrays.asList(RegressionModels.EXTREME_RANDOM_TREES, RegressionModels.ELASTIC_NET)))
                .withCvSplitColumnNames(Arrays.asList("zydisnuep", "wyj", "nldpxottd"))
                .withFeaturizationSettings(
                    new TableVerticalFeaturizationSettings()
                        .withDatasetLanguage("mzhwilzzhni")
                        .withBlockedTransformers(
                            Arrays.asList(BlockedTransformers.COUNT_VECTORIZER, BlockedTransformers.WO_ETARGET_ENCODER))
                        .withColumnNameAndTypes(mapOf("vcjwqwoqsratj", "zjihweebiphr", "jhfrzgdkkagv", "dhzybsp"))
                        .withEnableDnnFeaturization(true)
                        .withMode(FeaturizationMode.CUSTOM)
                        .withTransformerParams(mapOf("mo", Arrays.asList())))
                .withLimitSettings(
                    new TableVerticalLimitSettings()
                        .withEnableEarlyTermination(true)
                        .withExitScore(3.9502204468192637D)
                        .withMaxConcurrentTrials(2133816848)
                        .withMaxCoresPerTrial(444992966)
                        .withMaxTrials(1238035913)
                        .withTimeout(Duration.parse("PT160H46M45S"))
                        .withTrialTimeout(Duration.parse("PT11H57M31S")))
                .withNCrossValidations(new NCrossValidations())
                .withTestData(
                    new MLTableJobInput()
                        .withDescription("mltwjfluxynbpvzl")
                        .withMode(InputDeliveryMode.EVAL_DOWNLOAD)
                        .withUri("bkut"))
                .withTestDataSize(9.59052197916832D)
                .withValidationData(
                    new MLTableJobInput()
                        .withDescription("mocgjshg")
                        .withMode(InputDeliveryMode.EVAL_MOUNT)
                        .withUri("njc"))
                .withValidationDataSize(1.3885888922809064D)
                .withWeightColumnName("wvixq");
        model = BinaryData.fromObject(model).toObject(Regression.class);
        Assertions.assertEquals(LogVerbosity.ERROR, model.logVerbosity());
        Assertions.assertEquals("jkyb", model.targetColumnName());
        Assertions.assertEquals("hxpcvrdnyeita", model.trainingData().description());
        Assertions.assertEquals(InputDeliveryMode.READ_WRITE_MOUNT, model.trainingData().mode());
        Assertions.assertEquals("clrvtzqnrbctbh", model.trainingData().uri());
        Assertions.assertEquals(RegressionPrimaryMetrics.NORMALIZED_ROOT_MEAN_SQUARED_ERROR, model.primaryMetric());
        Assertions.assertEquals(false, model.trainingSettings().enableDnnTraining());
        Assertions.assertEquals(false, model.trainingSettings().enableModelExplainability());
        Assertions.assertEquals(false, model.trainingSettings().enableOnnxCompatibleModels());
        Assertions.assertEquals(true, model.trainingSettings().enableStackEnsemble());
        Assertions.assertEquals(false, model.trainingSettings().enableVoteEnsemble());
        Assertions.assertEquals(Duration.parse("PT84H43M30S"), model.trainingSettings().ensembleModelDownloadTimeout());
        Assertions
            .assertEquals(
                29.842412252567886D,
                model.trainingSettings().stackEnsembleSettings().stackMetaLearnerTrainPercentage());
        Assertions
            .assertEquals(
                StackMetaLearnerType.LIGHT_GBMREGRESSOR,
                model.trainingSettings().stackEnsembleSettings().stackMetaLearnerType());
        Assertions
            .assertEquals(RegressionModels.ELASTIC_NET, model.trainingSettings().allowedTrainingAlgorithms().get(0));
        Assertions
            .assertEquals(
                RegressionModels.EXTREME_RANDOM_TREES, model.trainingSettings().blockedTrainingAlgorithms().get(0));
        Assertions.assertEquals("zydisnuep", model.cvSplitColumnNames().get(0));
        Assertions.assertEquals("mzhwilzzhni", model.featurizationSettings().datasetLanguage());
        Assertions
            .assertEquals(
                BlockedTransformers.COUNT_VECTORIZER, model.featurizationSettings().blockedTransformers().get(0));
        Assertions
            .assertEquals("zjihweebiphr", model.featurizationSettings().columnNameAndTypes().get("vcjwqwoqsratj"));
        Assertions.assertEquals(true, model.featurizationSettings().enableDnnFeaturization());
        Assertions.assertEquals(FeaturizationMode.CUSTOM, model.featurizationSettings().mode());
        Assertions.assertEquals(true, model.limitSettings().enableEarlyTermination());
        Assertions.assertEquals(3.9502204468192637D, model.limitSettings().exitScore());
        Assertions.assertEquals(2133816848, model.limitSettings().maxConcurrentTrials());
        Assertions.assertEquals(444992966, model.limitSettings().maxCoresPerTrial());
        Assertions.assertEquals(1238035913, model.limitSettings().maxTrials());
        Assertions.assertEquals(Duration.parse("PT160H46M45S"), model.limitSettings().timeout());
        Assertions.assertEquals(Duration.parse("PT11H57M31S"), model.limitSettings().trialTimeout());
        Assertions.assertEquals("mltwjfluxynbpvzl", model.testData().description());
        Assertions.assertEquals(InputDeliveryMode.EVAL_DOWNLOAD, model.testData().mode());
        Assertions.assertEquals("bkut", model.testData().uri());
        Assertions.assertEquals(9.59052197916832D, model.testDataSize());
        Assertions.assertEquals("mocgjshg", model.validationData().description());
        Assertions.assertEquals(InputDeliveryMode.EVAL_MOUNT, model.validationData().mode());
        Assertions.assertEquals("njc", model.validationData().uri());
        Assertions.assertEquals(1.3885888922809064D, model.validationDataSize());
        Assertions.assertEquals("wvixq", model.weightColumnName());
    }

    @SuppressWarnings("unchecked")
    private static <T> Map<String, T> mapOf(Object... inputs) {
        Map<String, T> map = new HashMap<>();
        for (int i = 0; i < inputs.length; i += 2) {
            String key = (String) inputs[i];
            T value = (T) inputs[i + 1];
            map.put(key, value);
        }
        return map;
    }
}
