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

package com.azure.resourcemanager.nginx.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.nginx.fluent.models.NginxDeploymentInner;
import com.azure.resourcemanager.nginx.models.IdentityProperties;
import com.azure.resourcemanager.nginx.models.IdentityType;
import com.azure.resourcemanager.nginx.models.NginxDeploymentProperties;
import com.azure.resourcemanager.nginx.models.NginxLogging;
import com.azure.resourcemanager.nginx.models.NginxNetworkProfile;
import com.azure.resourcemanager.nginx.models.ResourceSku;
import com.azure.resourcemanager.nginx.models.UserIdentityProperties;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class NginxDeploymentInnerTests {
    @Test
    public void testDeserialize() {
        NginxDeploymentInner model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"principalId\":\"krwpdap\",\"tenantId\":\"sbdkvwr\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"phut\":{\"principalId\":\"nhutjeltmrldhugj\",\"clientId\":\"datqxhocdgeabl\"},\"ftyxolniw\":{\"principalId\":\"ndv\",\"clientId\":\"ozwyiftyhxhuro\"}}},\"properties\":{\"provisioningState\":\"Accepted\",\"nginxVersion\":\"jfkgiawxk\",\"managedResourceGroup\":\"ypl\",\"networkProfile\":{},\"ipAddress\":\"syyp\",\"enableDiagnosticsSupport\":false,\"logging\":{}},\"sku\":{\"name\":\"cbacphejkotynqg\"},\"location\":\"l\",\"tags\":{\"adgakeqsrxybz\":\"likwyqkgfgib\",\"mnkzsmod\":\"qedqytbciqfoufl\",\"tmut\":\"glougpbk\",\"pwgcuertu\":\"uqktap\"},\"id\":\"kdosvqw\",\"name\":\"bmdg\",\"type\":\"bjf\"}")
                .toObject(NginxDeploymentInner.class);
        Assertions.assertEquals("l", model.location());
        Assertions.assertEquals("likwyqkgfgib", model.tags().get("adgakeqsrxybz"));
        Assertions.assertEquals(IdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("ypl", model.properties().managedResourceGroup());
        Assertions.assertEquals(false, model.properties().enableDiagnosticsSupport());
        Assertions.assertEquals("cbacphejkotynqg", model.sku().name());
    }

    @Test
    public void testSerialize() {
        NginxDeploymentInner model =
            new NginxDeploymentInner()
                .withLocation("l")
                .withTags(
                    mapOf(
                        "adgakeqsrxybz",
                        "likwyqkgfgib",
                        "mnkzsmod",
                        "qedqytbciqfoufl",
                        "tmut",
                        "glougpbk",
                        "pwgcuertu",
                        "uqktap"))
                .withIdentity(
                    new IdentityProperties()
                        .withType(IdentityType.USER_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf("phut", new UserIdentityProperties(), "ftyxolniw", new UserIdentityProperties())))
                .withProperties(
                    new NginxDeploymentProperties()
                        .withManagedResourceGroup("ypl")
                        .withNetworkProfile(new NginxNetworkProfile())
                        .withEnableDiagnosticsSupport(false)
                        .withLogging(new NginxLogging()))
                .withSku(new ResourceSku().withName("cbacphejkotynqg"));
        model = BinaryData.fromObject(model).toObject(NginxDeploymentInner.class);
        Assertions.assertEquals("l", model.location());
        Assertions.assertEquals("likwyqkgfgib", model.tags().get("adgakeqsrxybz"));
        Assertions.assertEquals(IdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("ypl", model.properties().managedResourceGroup());
        Assertions.assertEquals(false, model.properties().enableDiagnosticsSupport());
        Assertions.assertEquals("cbacphejkotynqg", model.sku().name());
    }

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