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

package com.azure.resourcemanager.deploymentmanager.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.deploymentmanager.fluent.models.RolloutInner;
import com.azure.resourcemanager.deploymentmanager.models.Identity;
import com.azure.resourcemanager.deploymentmanager.models.StepGroup;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class RolloutInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        RolloutInner model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"type\":\"tumkdosvqwhbm\",\"identityIds\":[\"bbjfddgmbmbexp\",\"bhtqqrolfpfpsa\",\"gbquxigj\",\"jgzjaoyfhrtx\"]},\"properties\":{\"status\":\"erkujys\",\"totalRetryAttempts\":709635131,\"operationInfo\":{\"retryAttempt\":1644570632,\"skipSucceededOnRetry\":true,\"startTime\":\"2021-11-11T16:20:30Z\",\"endTime\":\"2021-11-26T22:23:23Z\"},\"services\":[{\"name\":\"kcprbnw\",\"serviceUnits\":[],\"targetLocation\":\"gjvtbv\",\"targetSubscriptionId\":\"ysszdnrujqguh\"},{\"name\":\"ouqfprwz\",\"serviceUnits\":[],\"targetLocation\":\"nguitnwuizgazxu\",\"targetSubscriptionId\":\"izuckyfihrfidfvz\"}],\"buildVersion\":\"dzuhtymwi\",\"artifactSourceId\":\"kfthwxmntei\",\"targetServiceTopologyId\":\"aop\",\"stepGroups\":[{\"name\":\"mijcmmxdcufufs\",\"dependsOnStepGroups\":[],\"preDeploymentSteps\":[],\"deploymentTargetId\":\"mzidnsezcxtb\",\"postDeploymentSteps\":[]}]},\"location\":\"gfycc\",\"tags\":{\"flnrosfqpteehzz\":\"wmdwzjeiachboo\",\"swjdkirso\":\"ypyqrimzinp\"},\"id\":\"dqxhcrmnohjtckwh\",\"name\":\"soifiyipjxsqw\",\"type\":\"gr\"}")
                .toObject(RolloutInner.class);
        Assertions.assertEquals("gfycc", model.location());
        Assertions.assertEquals("wmdwzjeiachboo", model.tags().get("flnrosfqpteehzz"));
        Assertions.assertEquals("tumkdosvqwhbm", model.identity().type());
        Assertions.assertEquals("bbjfddgmbmbexp", model.identity().identityIds().get(0));
        Assertions.assertEquals("dzuhtymwi", model.buildVersion());
        Assertions.assertEquals("kfthwxmntei", model.artifactSourceId());
        Assertions.assertEquals("aop", model.targetServiceTopologyId());
        Assertions.assertEquals("mijcmmxdcufufs", model.stepGroups().get(0).name());
        Assertions.assertEquals("mzidnsezcxtb", model.stepGroups().get(0).deploymentTargetId());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        RolloutInner model =
            new RolloutInner()
                .withLocation("gfycc")
                .withTags(mapOf("flnrosfqpteehzz", "wmdwzjeiachboo", "swjdkirso", "ypyqrimzinp"))
                .withIdentity(
                    new Identity()
                        .withType("tumkdosvqwhbm")
                        .withIdentityIds(Arrays.asList("bbjfddgmbmbexp", "bhtqqrolfpfpsa", "gbquxigj", "jgzjaoyfhrtx")))
                .withBuildVersion("dzuhtymwi")
                .withArtifactSourceId("kfthwxmntei")
                .withTargetServiceTopologyId("aop")
                .withStepGroups(
                    Arrays
                        .asList(
                            new StepGroup()
                                .withName("mijcmmxdcufufs")
                                .withDependsOnStepGroups(Arrays.asList())
                                .withPreDeploymentSteps(Arrays.asList())
                                .withDeploymentTargetId("mzidnsezcxtb")
                                .withPostDeploymentSteps(Arrays.asList())));
        model = BinaryData.fromObject(model).toObject(RolloutInner.class);
        Assertions.assertEquals("gfycc", model.location());
        Assertions.assertEquals("wmdwzjeiachboo", model.tags().get("flnrosfqpteehzz"));
        Assertions.assertEquals("tumkdosvqwhbm", model.identity().type());
        Assertions.assertEquals("bbjfddgmbmbexp", model.identity().identityIds().get(0));
        Assertions.assertEquals("dzuhtymwi", model.buildVersion());
        Assertions.assertEquals("kfthwxmntei", model.artifactSourceId());
        Assertions.assertEquals("aop", model.targetServiceTopologyId());
        Assertions.assertEquals("mijcmmxdcufufs", model.stepGroups().get(0).name());
        Assertions.assertEquals("mzidnsezcxtb", model.stepGroups().get(0).deploymentTargetId());
    }

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