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

package com.azure.resourcemanager.servicefabric.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.servicefabric.models.DurabilityLevel;
import com.azure.resourcemanager.servicefabric.models.EndpointRangeDescription;
import com.azure.resourcemanager.servicefabric.models.NodeTypeDescription;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class NodeTypeDescriptionTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        NodeTypeDescription model =
            BinaryData
                .fromString(
                    "{\"name\":\"u\",\"placementProperties\":{\"nwzsymg\":\"ryrtihfxtijbpzv\",\"anufhfcbjysag\":\"zufcyzkohdbi\"},\"capacities\":{\"pikxwczbyscnpqxu\":\"xqhabi\"},\"clientConnectionEndpointPort\":1646115006,\"httpGatewayEndpointPort\":800348188,\"durabilityLevel\":\"Silver\",\"applicationPorts\":{\"startPort\":1574574303,\"endPort\":649847293},\"ephemeralPorts\":{\"startPort\":992034682,\"endPort\":355535904},\"isPrimary\":false,\"vmInstanceCount\":143848779,\"reverseProxyEndpointPort\":519347031,\"isStateless\":true,\"multipleAvailabilityZones\":true}")
                .toObject(NodeTypeDescription.class);
        Assertions.assertEquals("u", model.name());
        Assertions.assertEquals("ryrtihfxtijbpzv", model.placementProperties().get("nwzsymg"));
        Assertions.assertEquals("xqhabi", model.capacities().get("pikxwczbyscnpqxu"));
        Assertions.assertEquals(1646115006, model.clientConnectionEndpointPort());
        Assertions.assertEquals(800348188, model.httpGatewayEndpointPort());
        Assertions.assertEquals(DurabilityLevel.SILVER, model.durabilityLevel());
        Assertions.assertEquals(1574574303, model.applicationPorts().startPort());
        Assertions.assertEquals(649847293, model.applicationPorts().endPort());
        Assertions.assertEquals(992034682, model.ephemeralPorts().startPort());
        Assertions.assertEquals(355535904, model.ephemeralPorts().endPort());
        Assertions.assertEquals(false, model.isPrimary());
        Assertions.assertEquals(143848779, model.vmInstanceCount());
        Assertions.assertEquals(519347031, model.reverseProxyEndpointPort());
        Assertions.assertEquals(true, model.isStateless());
        Assertions.assertEquals(true, model.multipleAvailabilityZones());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        NodeTypeDescription model =
            new NodeTypeDescription()
                .withName("u")
                .withPlacementProperties(mapOf("nwzsymg", "ryrtihfxtijbpzv", "anufhfcbjysag", "zufcyzkohdbi"))
                .withCapacities(mapOf("pikxwczbyscnpqxu", "xqhabi"))
                .withClientConnectionEndpointPort(1646115006)
                .withHttpGatewayEndpointPort(800348188)
                .withDurabilityLevel(DurabilityLevel.SILVER)
                .withApplicationPorts(new EndpointRangeDescription().withStartPort(1574574303).withEndPort(649847293))
                .withEphemeralPorts(new EndpointRangeDescription().withStartPort(992034682).withEndPort(355535904))
                .withIsPrimary(false)
                .withVmInstanceCount(143848779)
                .withReverseProxyEndpointPort(519347031)
                .withIsStateless(true)
                .withMultipleAvailabilityZones(true);
        model = BinaryData.fromObject(model).toObject(NodeTypeDescription.class);
        Assertions.assertEquals("u", model.name());
        Assertions.assertEquals("ryrtihfxtijbpzv", model.placementProperties().get("nwzsymg"));
        Assertions.assertEquals("xqhabi", model.capacities().get("pikxwczbyscnpqxu"));
        Assertions.assertEquals(1646115006, model.clientConnectionEndpointPort());
        Assertions.assertEquals(800348188, model.httpGatewayEndpointPort());
        Assertions.assertEquals(DurabilityLevel.SILVER, model.durabilityLevel());
        Assertions.assertEquals(1574574303, model.applicationPorts().startPort());
        Assertions.assertEquals(649847293, model.applicationPorts().endPort());
        Assertions.assertEquals(992034682, model.ephemeralPorts().startPort());
        Assertions.assertEquals(355535904, model.ephemeralPorts().endPort());
        Assertions.assertEquals(false, model.isPrimary());
        Assertions.assertEquals(143848779, model.vmInstanceCount());
        Assertions.assertEquals(519347031, model.reverseProxyEndpointPort());
        Assertions.assertEquals(true, model.isStateless());
        Assertions.assertEquals(true, model.multipleAvailabilityZones());
    }

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