// 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.MLTableJobInput;
import com.azure.resourcemanager.machinelearning.models.NCrossValidations;
import com.azure.resourcemanager.machinelearning.models.TableVertical;
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 TableVerticalTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        TableVertical model =
            BinaryData
                .fromString(
                    "{\"cvSplitColumnNames\":[\"aqkue\",\"tgroesh\"],\"featurizationSettings\":{\"blockedTransformers\":[\"LabelEncoder\",\"CountVectorizer\"],\"columnNameAndTypes\":{\"vjmvqmtdwckygr\":\"qxkfaoytehqp\",\"kb\":\"ejnndljdju\",\"n\":\"req\"},\"enableDnnFeaturization\":true,\"mode\":\"Auto\",\"transformerParams\":{\"egplwr\":[]},\"datasetLanguage\":\"hwddkvbxgkq\"},\"limitSettings\":{\"enableEarlyTermination\":true,\"exitScore\":58.74936526740298,\"maxConcurrentTrials\":1893356146,\"maxCoresPerTrial\":1883292844,\"maxTrials\":501930478,\"timeout\":\"PT193H51M55S\",\"trialTimeout\":\"PT46H37M35S\"},\"nCrossValidations\":{\"mode\":\"NCrossValidations\"},\"testData\":{\"jobInputType\":\"mltable\",\"mode\":\"ReadOnlyMount\",\"uri\":\"poi\",\"description\":\"naz\"},\"testDataSize\":59.15029219925634,\"validationData\":{\"jobInputType\":\"mltable\",\"mode\":\"Direct\",\"uri\":\"qalsxkd\",\"description\":\"qapfgsdpc\"},\"validationDataSize\":60.92552835591164,\"weightColumnName\":\"zhhkuuipldqqc\"}")
                .toObject(TableVertical.class);
        Assertions.assertEquals("aqkue", model.cvSplitColumnNames().get(0));
        Assertions.assertEquals("hwddkvbxgkq", model.featurizationSettings().datasetLanguage());
        Assertions
            .assertEquals(
                BlockedTransformers.LABEL_ENCODER, model.featurizationSettings().blockedTransformers().get(0));
        Assertions
            .assertEquals("qxkfaoytehqp", model.featurizationSettings().columnNameAndTypes().get("vjmvqmtdwckygr"));
        Assertions.assertEquals(true, model.featurizationSettings().enableDnnFeaturization());
        Assertions.assertEquals(FeaturizationMode.AUTO, model.featurizationSettings().mode());
        Assertions.assertEquals(true, model.limitSettings().enableEarlyTermination());
        Assertions.assertEquals(58.74936526740298D, model.limitSettings().exitScore());
        Assertions.assertEquals(1893356146, model.limitSettings().maxConcurrentTrials());
        Assertions.assertEquals(1883292844, model.limitSettings().maxCoresPerTrial());
        Assertions.assertEquals(501930478, model.limitSettings().maxTrials());
        Assertions.assertEquals(Duration.parse("PT193H51M55S"), model.limitSettings().timeout());
        Assertions.assertEquals(Duration.parse("PT46H37M35S"), model.limitSettings().trialTimeout());
        Assertions.assertEquals("naz", model.testData().description());
        Assertions.assertEquals(InputDeliveryMode.READ_ONLY_MOUNT, model.testData().mode());
        Assertions.assertEquals("poi", model.testData().uri());
        Assertions.assertEquals(59.15029219925634D, model.testDataSize());
        Assertions.assertEquals("qapfgsdpc", model.validationData().description());
        Assertions.assertEquals(InputDeliveryMode.DIRECT, model.validationData().mode());
        Assertions.assertEquals("qalsxkd", model.validationData().uri());
        Assertions.assertEquals(60.92552835591164D, model.validationDataSize());
        Assertions.assertEquals("zhhkuuipldqqc", model.weightColumnName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        TableVertical model =
            new TableVertical()
                .withCvSplitColumnNames(Arrays.asList("aqkue", "tgroesh"))
                .withFeaturizationSettings(
                    new TableVerticalFeaturizationSettings()
                        .withDatasetLanguage("hwddkvbxgkq")
                        .withBlockedTransformers(
                            Arrays.asList(BlockedTransformers.LABEL_ENCODER, BlockedTransformers.COUNT_VECTORIZER))
                        .withColumnNameAndTypes(mapOf("vjmvqmtdwckygr", "qxkfaoytehqp", "kb", "ejnndljdju", "n", "req"))
                        .withEnableDnnFeaturization(true)
                        .withMode(FeaturizationMode.AUTO)
                        .withTransformerParams(mapOf("egplwr", Arrays.asList())))
                .withLimitSettings(
                    new TableVerticalLimitSettings()
                        .withEnableEarlyTermination(true)
                        .withExitScore(58.74936526740298D)
                        .withMaxConcurrentTrials(1893356146)
                        .withMaxCoresPerTrial(1883292844)
                        .withMaxTrials(501930478)
                        .withTimeout(Duration.parse("PT193H51M55S"))
                        .withTrialTimeout(Duration.parse("PT46H37M35S")))
                .withNCrossValidations(new NCrossValidations())
                .withTestData(
                    new MLTableJobInput()
                        .withDescription("naz")
                        .withMode(InputDeliveryMode.READ_ONLY_MOUNT)
                        .withUri("poi"))
                .withTestDataSize(59.15029219925634D)
                .withValidationData(
                    new MLTableJobInput()
                        .withDescription("qapfgsdpc")
                        .withMode(InputDeliveryMode.DIRECT)
                        .withUri("qalsxkd"))
                .withValidationDataSize(60.92552835591164D)
                .withWeightColumnName("zhhkuuipldqqc");
        model = BinaryData.fromObject(model).toObject(TableVertical.class);
        Assertions.assertEquals("aqkue", model.cvSplitColumnNames().get(0));
        Assertions.assertEquals("hwddkvbxgkq", model.featurizationSettings().datasetLanguage());
        Assertions
            .assertEquals(
                BlockedTransformers.LABEL_ENCODER, model.featurizationSettings().blockedTransformers().get(0));
        Assertions
            .assertEquals("qxkfaoytehqp", model.featurizationSettings().columnNameAndTypes().get("vjmvqmtdwckygr"));
        Assertions.assertEquals(true, model.featurizationSettings().enableDnnFeaturization());
        Assertions.assertEquals(FeaturizationMode.AUTO, model.featurizationSettings().mode());
        Assertions.assertEquals(true, model.limitSettings().enableEarlyTermination());
        Assertions.assertEquals(58.74936526740298D, model.limitSettings().exitScore());
        Assertions.assertEquals(1893356146, model.limitSettings().maxConcurrentTrials());
        Assertions.assertEquals(1883292844, model.limitSettings().maxCoresPerTrial());
        Assertions.assertEquals(501930478, model.limitSettings().maxTrials());
        Assertions.assertEquals(Duration.parse("PT193H51M55S"), model.limitSettings().timeout());
        Assertions.assertEquals(Duration.parse("PT46H37M35S"), model.limitSettings().trialTimeout());
        Assertions.assertEquals("naz", model.testData().description());
        Assertions.assertEquals(InputDeliveryMode.READ_ONLY_MOUNT, model.testData().mode());
        Assertions.assertEquals("poi", model.testData().uri());
        Assertions.assertEquals(59.15029219925634D, model.testDataSize());
        Assertions.assertEquals("qapfgsdpc", model.validationData().description());
        Assertions.assertEquals(InputDeliveryMode.DIRECT, model.validationData().mode());
        Assertions.assertEquals("qalsxkd", model.validationData().uri());
        Assertions.assertEquals(60.92552835591164D, model.validationDataSize());
        Assertions.assertEquals("zhhkuuipldqqc", 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;
    }
}
