// 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.fluent.models.CodeContainerInner;
import com.azure.resourcemanager.machinelearning.models.CodeContainerProperties;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class CodeContainerInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        CodeContainerInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"isArchived\":true,\"latestVersion\":\"zbhd\",\"nextVersion\":\"mlmz\",\"description\":\"oftrmaequia\",\"properties\":{\"nswhcc\":\"cslfaoqzpiyylha\",\"aivwitqscywu\":\"ph\"},\"tags\":{\"i\":\"oluhczbwemh\",\"wmsweypqwd\":\"sbrgz\",\"mkttlstvlzywem\":\"ggicccnxqhue\",\"lusiy\":\"zrncsdt\"}},\"id\":\"sfgytguslfead\",\"name\":\"ygqukyhejh\",\"type\":\"isxgfp\"}")
                .toObject(CodeContainerInner.class);
        Assertions.assertEquals("oftrmaequia", model.properties().description());
        Assertions.assertEquals("cslfaoqzpiyylha", model.properties().properties().get("nswhcc"));
        Assertions.assertEquals("oluhczbwemh", model.properties().tags().get("i"));
        Assertions.assertEquals(true, model.properties().isArchived());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        CodeContainerInner model =
            new CodeContainerInner()
                .withProperties(
                    new CodeContainerProperties()
                        .withDescription("oftrmaequia")
                        .withProperties(mapOf("nswhcc", "cslfaoqzpiyylha", "aivwitqscywu", "ph"))
                        .withTags(
                            mapOf(
                                "i",
                                "oluhczbwemh",
                                "wmsweypqwd",
                                "sbrgz",
                                "mkttlstvlzywem",
                                "ggicccnxqhue",
                                "lusiy",
                                "zrncsdt"))
                        .withIsArchived(true));
        model = BinaryData.fromObject(model).toObject(CodeContainerInner.class);
        Assertions.assertEquals("oftrmaequia", model.properties().description());
        Assertions.assertEquals("cslfaoqzpiyylha", model.properties().properties().get("nswhcc"));
        Assertions.assertEquals("oluhczbwemh", model.properties().tags().get("i"));
        Assertions.assertEquals(true, model.properties().isArchived());
    }

    @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;
    }
}
