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

package com.azure.resourcemanager.datamigration.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.datamigration.fluent.models.ProjectInner;
import com.azure.resourcemanager.datamigration.models.ProjectList;
import com.azure.resourcemanager.datamigration.models.ProjectSourcePlatform;
import com.azure.resourcemanager.datamigration.models.ProjectTargetPlatform;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ProjectListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ProjectList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"sourcePlatform\":\"SQL\",\"targetPlatform\":\"SQLDB\",\"creationTime\":\"2021-02-03T19:04:42Z\",\"databasesInfo\":[],\"provisioningState\":\"Succeeded\"},\"location\":\"wjdk\",\"tags\":{\"ohjtckw\":\"oodqxhcrm\",\"sqwpgrjb\":\"dsoifiyipj\",\"mocpc\":\"norcjxvsnbyxqab\",\"c\":\"shurzafbljjgpbto\"},\"id\":\"mkljavb\",\"name\":\"idtqajzyu\",\"type\":\"pku\"},{\"properties\":{\"sourcePlatform\":\"Unknown\",\"targetPlatform\":\"Unknown\",\"creationTime\":\"2021-01-07T15:53:39Z\",\"databasesInfo\":[],\"provisioningState\":\"Deleting\"},\"location\":\"epgzgqexz\",\"tags\":{\"glu\":\"xscpaierhhbc\"},\"id\":\"majtjaod\",\"name\":\"obnbdxkqpxokaj\",\"type\":\"onpimexgstxg\"}],\"nextLink\":\"odgmaajrmvdjwz\"}")
                .toObject(ProjectList.class);
        Assertions.assertEquals("wjdk", model.value().get(0).location());
        Assertions.assertEquals("oodqxhcrm", model.value().get(0).tags().get("ohjtckw"));
        Assertions.assertEquals(ProjectSourcePlatform.SQL, model.value().get(0).sourcePlatform());
        Assertions.assertEquals(ProjectTargetPlatform.SQLDB, model.value().get(0).targetPlatform());
        Assertions.assertEquals("odgmaajrmvdjwz", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ProjectList model =
            new ProjectList()
                .withValue(
                    Arrays
                        .asList(
                            new ProjectInner()
                                .withLocation("wjdk")
                                .withTags(
                                    mapOf(
                                        "ohjtckw",
                                        "oodqxhcrm",
                                        "sqwpgrjb",
                                        "dsoifiyipj",
                                        "mocpc",
                                        "norcjxvsnbyxqab",
                                        "c",
                                        "shurzafbljjgpbto"))
                                .withSourcePlatform(ProjectSourcePlatform.SQL)
                                .withTargetPlatform(ProjectTargetPlatform.SQLDB)
                                .withDatabasesInfo(Arrays.asList()),
                            new ProjectInner()
                                .withLocation("epgzgqexz")
                                .withTags(mapOf("glu", "xscpaierhhbc"))
                                .withSourcePlatform(ProjectSourcePlatform.UNKNOWN)
                                .withTargetPlatform(ProjectTargetPlatform.UNKNOWN)
                                .withDatabasesInfo(Arrays.asList())))
                .withNextLink("odgmaajrmvdjwz");
        model = BinaryData.fromObject(model).toObject(ProjectList.class);
        Assertions.assertEquals("wjdk", model.value().get(0).location());
        Assertions.assertEquals("oodqxhcrm", model.value().get(0).tags().get("ohjtckw"));
        Assertions.assertEquals(ProjectSourcePlatform.SQL, model.value().get(0).sourcePlatform());
        Assertions.assertEquals(ProjectTargetPlatform.SQLDB, model.value().get(0).targetPlatform());
        Assertions.assertEquals("odgmaajrmvdjwz", model.nextLink());
    }

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