// 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.MoveCost;
import com.azure.resourcemanager.servicefabric.models.ServiceCorrelationDescription;
import com.azure.resourcemanager.servicefabric.models.ServiceCorrelationScheme;
import com.azure.resourcemanager.servicefabric.models.ServiceLoadMetricDescription;
import com.azure.resourcemanager.servicefabric.models.ServiceLoadMetricWeight;
import com.azure.resourcemanager.servicefabric.models.ServicePlacementPolicyDescription;
import com.azure.resourcemanager.servicefabric.models.ServiceResourceUpdate;
import com.azure.resourcemanager.servicefabric.models.ServiceResourceUpdateProperties;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ServiceResourceUpdateTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ServiceResourceUpdate model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"serviceKind\":\"ServiceResourceUpdateProperties\",\"placementConstraints\":\"mond\",\"correlationScheme\":[{\"scheme\":\"NonAlignedAffinity\",\"serviceName\":\"xvy\"},{\"scheme\":\"AlignedAffinity\",\"serviceName\":\"mg\"},{\"scheme\":\"Affinity\",\"serviceName\":\"pkwhojvpa\"}],\"serviceLoadMetrics\":[{\"name\":\"xysmoc\",\"weight\":\"Low\",\"primaryDefaultLoad\":1729730350,\"secondaryDefaultLoad\":484454898,\"defaultLoad\":1023043004},{\"name\":\"xozap\",\"weight\":\"High\",\"primaryDefaultLoad\":760338850,\"secondaryDefaultLoad\":1009044014,\"defaultLoad\":599775917},{\"name\":\"yat\",\"weight\":\"Zero\",\"primaryDefaultLoad\":1454263457,\"secondaryDefaultLoad\":373907539,\"defaultLoad\":1344502344},{\"name\":\"jrjxgciqibrhosx\",\"weight\":\"High\",\"primaryDefaultLoad\":656063523,\"secondaryDefaultLoad\":218775906,\"defaultLoad\":212926113}],\"servicePlacementPolicies\":[{\"type\":\"ServicePlacementPolicyDescription\"},{\"type\":\"ServicePlacementPolicyDescription\"},{\"type\":\"ServicePlacementPolicyDescription\"}],\"defaultMoveCost\":\"Zero\"},\"location\":\"yiba\",\"tags\":{\"yvoqa\":\"luszdtmhrkwof\",\"wo\":\"piexpbtgiw\"},\"etag\":\"washr\",\"id\":\"tkcnqxwb\",\"name\":\"okulpiujwa\",\"type\":\"sipqii\"}")
                .toObject(ServiceResourceUpdate.class);
        Assertions.assertEquals("mond", model.properties().placementConstraints());
        Assertions
            .assertEquals(
                ServiceCorrelationScheme.NON_ALIGNED_AFFINITY, model.properties().correlationScheme().get(0).scheme());
        Assertions.assertEquals("xvy", model.properties().correlationScheme().get(0).serviceName());
        Assertions.assertEquals("xysmoc", model.properties().serviceLoadMetrics().get(0).name());
        Assertions.assertEquals(ServiceLoadMetricWeight.LOW, model.properties().serviceLoadMetrics().get(0).weight());
        Assertions.assertEquals(1729730350, model.properties().serviceLoadMetrics().get(0).primaryDefaultLoad());
        Assertions.assertEquals(484454898, model.properties().serviceLoadMetrics().get(0).secondaryDefaultLoad());
        Assertions.assertEquals(1023043004, model.properties().serviceLoadMetrics().get(0).defaultLoad());
        Assertions.assertEquals(MoveCost.ZERO, model.properties().defaultMoveCost());
        Assertions.assertEquals("yiba", model.location());
        Assertions.assertEquals("luszdtmhrkwof", model.tags().get("yvoqa"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ServiceResourceUpdate model =
            new ServiceResourceUpdate()
                .withProperties(
                    new ServiceResourceUpdateProperties()
                        .withPlacementConstraints("mond")
                        .withCorrelationScheme(
                            Arrays
                                .asList(
                                    new ServiceCorrelationDescription()
                                        .withScheme(ServiceCorrelationScheme.NON_ALIGNED_AFFINITY)
                                        .withServiceName("xvy"),
                                    new ServiceCorrelationDescription()
                                        .withScheme(ServiceCorrelationScheme.ALIGNED_AFFINITY)
                                        .withServiceName("mg"),
                                    new ServiceCorrelationDescription()
                                        .withScheme(ServiceCorrelationScheme.AFFINITY)
                                        .withServiceName("pkwhojvpa")))
                        .withServiceLoadMetrics(
                            Arrays
                                .asList(
                                    new ServiceLoadMetricDescription()
                                        .withName("xysmoc")
                                        .withWeight(ServiceLoadMetricWeight.LOW)
                                        .withPrimaryDefaultLoad(1729730350)
                                        .withSecondaryDefaultLoad(484454898)
                                        .withDefaultLoad(1023043004),
                                    new ServiceLoadMetricDescription()
                                        .withName("xozap")
                                        .withWeight(ServiceLoadMetricWeight.HIGH)
                                        .withPrimaryDefaultLoad(760338850)
                                        .withSecondaryDefaultLoad(1009044014)
                                        .withDefaultLoad(599775917),
                                    new ServiceLoadMetricDescription()
                                        .withName("yat")
                                        .withWeight(ServiceLoadMetricWeight.ZERO)
                                        .withPrimaryDefaultLoad(1454263457)
                                        .withSecondaryDefaultLoad(373907539)
                                        .withDefaultLoad(1344502344),
                                    new ServiceLoadMetricDescription()
                                        .withName("jrjxgciqibrhosx")
                                        .withWeight(ServiceLoadMetricWeight.HIGH)
                                        .withPrimaryDefaultLoad(656063523)
                                        .withSecondaryDefaultLoad(218775906)
                                        .withDefaultLoad(212926113)))
                        .withServicePlacementPolicies(
                            Arrays
                                .asList(
                                    new ServicePlacementPolicyDescription(),
                                    new ServicePlacementPolicyDescription(),
                                    new ServicePlacementPolicyDescription()))
                        .withDefaultMoveCost(MoveCost.ZERO))
                .withLocation("yiba")
                .withTags(mapOf("yvoqa", "luszdtmhrkwof", "wo", "piexpbtgiw"));
        model = BinaryData.fromObject(model).toObject(ServiceResourceUpdate.class);
        Assertions.assertEquals("mond", model.properties().placementConstraints());
        Assertions
            .assertEquals(
                ServiceCorrelationScheme.NON_ALIGNED_AFFINITY, model.properties().correlationScheme().get(0).scheme());
        Assertions.assertEquals("xvy", model.properties().correlationScheme().get(0).serviceName());
        Assertions.assertEquals("xysmoc", model.properties().serviceLoadMetrics().get(0).name());
        Assertions.assertEquals(ServiceLoadMetricWeight.LOW, model.properties().serviceLoadMetrics().get(0).weight());
        Assertions.assertEquals(1729730350, model.properties().serviceLoadMetrics().get(0).primaryDefaultLoad());
        Assertions.assertEquals(484454898, model.properties().serviceLoadMetrics().get(0).secondaryDefaultLoad());
        Assertions.assertEquals(1023043004, model.properties().serviceLoadMetrics().get(0).defaultLoad());
        Assertions.assertEquals(MoveCost.ZERO, model.properties().defaultMoveCost());
        Assertions.assertEquals("yiba", model.location());
        Assertions.assertEquals("luszdtmhrkwof", model.tags().get("yvoqa"));
    }

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