// 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.ServiceUnitResourceInner;
import com.azure.resourcemanager.deploymentmanager.models.DeploymentMode;
import com.azure.resourcemanager.deploymentmanager.models.ServiceUnitArtifacts;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ServiceUnitResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ServiceUnitResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"targetResourceGroup\":\"kc\",\"deploymentMode\":\"Complete\",\"artifacts\":{\"templateUri\":\"rcryuanzwuxzdxta\",\"parametersUri\":\"lhmwhfpmrqobm\",\"templateArtifactSourceRelativePath\":\"kknryrtihf\",\"parametersArtifactSourceRelativePath\":\"ijbpzvgnwzsymgl\"}},\"location\":\"uf\",\"tags\":{\"ufhfcbjysa\":\"kohdbiha\"},\"id\":\"ithxqhabifpi\",\"name\":\"xwczbyscnp\",\"type\":\"x\"}")
                .toObject(ServiceUnitResourceInner.class);
        Assertions.assertEquals("uf", model.location());
        Assertions.assertEquals("kohdbiha", model.tags().get("ufhfcbjysa"));
        Assertions.assertEquals("kc", model.targetResourceGroup());
        Assertions.assertEquals(DeploymentMode.COMPLETE, model.deploymentMode());
        Assertions.assertEquals("rcryuanzwuxzdxta", model.artifacts().templateUri());
        Assertions.assertEquals("lhmwhfpmrqobm", model.artifacts().parametersUri());
        Assertions.assertEquals("kknryrtihf", model.artifacts().templateArtifactSourceRelativePath());
        Assertions.assertEquals("ijbpzvgnwzsymgl", model.artifacts().parametersArtifactSourceRelativePath());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ServiceUnitResourceInner model =
            new ServiceUnitResourceInner()
                .withLocation("uf")
                .withTags(mapOf("ufhfcbjysa", "kohdbiha"))
                .withTargetResourceGroup("kc")
                .withDeploymentMode(DeploymentMode.COMPLETE)
                .withArtifacts(
                    new ServiceUnitArtifacts()
                        .withTemplateUri("rcryuanzwuxzdxta")
                        .withParametersUri("lhmwhfpmrqobm")
                        .withTemplateArtifactSourceRelativePath("kknryrtihf")
                        .withParametersArtifactSourceRelativePath("ijbpzvgnwzsymgl"));
        model = BinaryData.fromObject(model).toObject(ServiceUnitResourceInner.class);
        Assertions.assertEquals("uf", model.location());
        Assertions.assertEquals("kohdbiha", model.tags().get("ufhfcbjysa"));
        Assertions.assertEquals("kc", model.targetResourceGroup());
        Assertions.assertEquals(DeploymentMode.COMPLETE, model.deploymentMode());
        Assertions.assertEquals("rcryuanzwuxzdxta", model.artifacts().templateUri());
        Assertions.assertEquals("lhmwhfpmrqobm", model.artifacts().parametersUri());
        Assertions.assertEquals("kknryrtihf", model.artifacts().templateArtifactSourceRelativePath());
        Assertions.assertEquals("ijbpzvgnwzsymgl", model.artifacts().parametersArtifactSourceRelativePath());
    }

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