// 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.RolloutRequestInner;
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 RolloutRequestInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        RolloutRequestInner model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"type\":\"wfzitonpeqfpjk\",\"identityIds\":[\"xofpdvhpfxxypi\",\"i\",\"mayhuybbkpodepoo\",\"inuvamiheogn\"]},\"properties\":{\"buildVersion\":\"rxzxtheo\",\"artifactSourceId\":\"si\",\"targetServiceTopologyId\":\"yevc\",\"stepGroups\":[{\"name\":\"qi\",\"dependsOnStepGroups\":[],\"preDeploymentSteps\":[],\"deploymentTargetId\":\"un\",\"postDeploymentSteps\":[]},{\"name\":\"wjzrnfygxgisp\",\"dependsOnStepGroups\":[],\"preDeploymentSteps\":[],\"deploymentTargetId\":\"tzfkufubl\",\"postDeploymentSteps\":[]}]},\"location\":\"fxqeof\",\"tags\":{\"msmjqulngsntn\":\"qjhqjbas\"},\"id\":\"ybkzgcwr\",\"name\":\"clxxwrljdo\",\"type\":\"skcqvkocrcjd\"}")
                .toObject(RolloutRequestInner.class);
        Assertions.assertEquals("fxqeof", model.location());
        Assertions.assertEquals("qjhqjbas", model.tags().get("msmjqulngsntn"));
        Assertions.assertEquals("wfzitonpeqfpjk", model.identity().type());
        Assertions.assertEquals("xofpdvhpfxxypi", model.identity().identityIds().get(0));
        Assertions.assertEquals("rxzxtheo", model.buildVersion());
        Assertions.assertEquals("si", model.artifactSourceId());
        Assertions.assertEquals("yevc", model.targetServiceTopologyId());
        Assertions.assertEquals("qi", model.stepGroups().get(0).name());
        Assertions.assertEquals("un", model.stepGroups().get(0).deploymentTargetId());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        RolloutRequestInner model =
            new RolloutRequestInner()
                .withLocation("fxqeof")
                .withTags(mapOf("msmjqulngsntn", "qjhqjbas"))
                .withIdentity(
                    new Identity()
                        .withType("wfzitonpeqfpjk")
                        .withIdentityIds(Arrays.asList("xofpdvhpfxxypi", "i", "mayhuybbkpodepoo", "inuvamiheogn")))
                .withBuildVersion("rxzxtheo")
                .withArtifactSourceId("si")
                .withTargetServiceTopologyId("yevc")
                .withStepGroups(
                    Arrays
                        .asList(
                            new StepGroup()
                                .withName("qi")
                                .withDependsOnStepGroups(Arrays.asList())
                                .withPreDeploymentSteps(Arrays.asList())
                                .withDeploymentTargetId("un")
                                .withPostDeploymentSteps(Arrays.asList()),
                            new StepGroup()
                                .withName("wjzrnfygxgisp")
                                .withDependsOnStepGroups(Arrays.asList())
                                .withPreDeploymentSteps(Arrays.asList())
                                .withDeploymentTargetId("tzfkufubl")
                                .withPostDeploymentSteps(Arrays.asList())));
        model = BinaryData.fromObject(model).toObject(RolloutRequestInner.class);
        Assertions.assertEquals("fxqeof", model.location());
        Assertions.assertEquals("qjhqjbas", model.tags().get("msmjqulngsntn"));
        Assertions.assertEquals("wfzitonpeqfpjk", model.identity().type());
        Assertions.assertEquals("xofpdvhpfxxypi", model.identity().identityIds().get(0));
        Assertions.assertEquals("rxzxtheo", model.buildVersion());
        Assertions.assertEquals("si", model.artifactSourceId());
        Assertions.assertEquals("yevc", model.targetServiceTopologyId());
        Assertions.assertEquals("qi", model.stepGroups().get(0).name());
        Assertions.assertEquals("un", 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;
    }
}
