// 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.fluent.models.ServiceResourceInner;
import com.azure.resourcemanager.servicefabric.models.ArmServicePackageActivationMode;
import com.azure.resourcemanager.servicefabric.models.MoveCost;
import com.azure.resourcemanager.servicefabric.models.PartitionSchemeDescription;
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.ServiceResourceProperties;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ServiceResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ServiceResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"serviceKind\":\"ServiceResourceProperties\",\"provisioningState\":\"zpyqsemwab\",\"serviceTypeName\":\"tshhszhedp\",\"partitionDescription\":{\"partitionScheme\":\"PartitionSchemeDescription\"},\"servicePackageActivationMode\":\"ExclusiveProcess\",\"serviceDnsName\":\"ubmwmbesld\",\"placementConstraints\":\"wwtppj\",\"correlationScheme\":[{\"scheme\":\"NonAlignedAffinity\",\"serviceName\":\"ogaok\"},{\"scheme\":\"AlignedAffinity\",\"serviceName\":\"z\"},{\"scheme\":\"NonAlignedAffinity\",\"serviceName\":\"sikvmkqzeqqkdlt\"}],\"serviceLoadMetrics\":[{\"name\":\"mhhv\",\"weight\":\"Zero\",\"primaryDefaultLoad\":243631399,\"secondaryDefaultLoad\":191107441,\"defaultLoad\":1245356368},{\"name\":\"obdagxtibqdxb\",\"weight\":\"High\",\"primaryDefaultLoad\":1383778705,\"secondaryDefaultLoad\":2040328424,\"defaultLoad\":431399757},{\"name\":\"ndlkzgxhurip\",\"weight\":\"Low\",\"primaryDefaultLoad\":1784018500,\"secondaryDefaultLoad\":1806634279,\"defaultLoad\":2086660215}],\"servicePlacementPolicies\":[{\"type\":\"ServicePlacementPolicyDescription\"},{\"type\":\"ServicePlacementPolicyDescription\"},{\"type\":\"ServicePlacementPolicyDescription\"}],\"defaultMoveCost\":\"High\"},\"location\":\"ubyyntw\",\"tags\":{\"otgqrlltmu\":\"qtkoievs\",\"zmuvpbttdumorppx\":\"lauwzizxbmpgcjef\",\"fgohdneuelfphs\":\"bmnzbtbhjpgl\",\"v\":\"yhtozfikdowwqu\"},\"etag\":\"xclvit\",\"id\":\"qzonosggbhcohf\",\"name\":\"dsjnka\",\"type\":\"jutiiswacff\"}")
                .toObject(ServiceResourceInner.class);
        Assertions.assertEquals("wwtppj", model.properties().placementConstraints());
        Assertions
            .assertEquals(
                ServiceCorrelationScheme.NON_ALIGNED_AFFINITY, model.properties().correlationScheme().get(0).scheme());
        Assertions.assertEquals("ogaok", model.properties().correlationScheme().get(0).serviceName());
        Assertions.assertEquals("mhhv", model.properties().serviceLoadMetrics().get(0).name());
        Assertions.assertEquals(ServiceLoadMetricWeight.ZERO, model.properties().serviceLoadMetrics().get(0).weight());
        Assertions.assertEquals(243631399, model.properties().serviceLoadMetrics().get(0).primaryDefaultLoad());
        Assertions.assertEquals(191107441, model.properties().serviceLoadMetrics().get(0).secondaryDefaultLoad());
        Assertions.assertEquals(1245356368, model.properties().serviceLoadMetrics().get(0).defaultLoad());
        Assertions.assertEquals(MoveCost.HIGH, model.properties().defaultMoveCost());
        Assertions.assertEquals("tshhszhedp", model.properties().serviceTypeName());
        Assertions
            .assertEquals(
                ArmServicePackageActivationMode.EXCLUSIVE_PROCESS, model.properties().servicePackageActivationMode());
        Assertions.assertEquals("ubmwmbesld", model.properties().serviceDnsName());
        Assertions.assertEquals("ubyyntw", model.location());
        Assertions.assertEquals("qtkoievs", model.tags().get("otgqrlltmu"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ServiceResourceInner model =
            new ServiceResourceInner()
                .withProperties(
                    new ServiceResourceProperties()
                        .withPlacementConstraints("wwtppj")
                        .withCorrelationScheme(
                            Arrays
                                .asList(
                                    new ServiceCorrelationDescription()
                                        .withScheme(ServiceCorrelationScheme.NON_ALIGNED_AFFINITY)
                                        .withServiceName("ogaok"),
                                    new ServiceCorrelationDescription()
                                        .withScheme(ServiceCorrelationScheme.ALIGNED_AFFINITY)
                                        .withServiceName("z"),
                                    new ServiceCorrelationDescription()
                                        .withScheme(ServiceCorrelationScheme.NON_ALIGNED_AFFINITY)
                                        .withServiceName("sikvmkqzeqqkdlt")))
                        .withServiceLoadMetrics(
                            Arrays
                                .asList(
                                    new ServiceLoadMetricDescription()
                                        .withName("mhhv")
                                        .withWeight(ServiceLoadMetricWeight.ZERO)
                                        .withPrimaryDefaultLoad(243631399)
                                        .withSecondaryDefaultLoad(191107441)
                                        .withDefaultLoad(1245356368),
                                    new ServiceLoadMetricDescription()
                                        .withName("obdagxtibqdxb")
                                        .withWeight(ServiceLoadMetricWeight.HIGH)
                                        .withPrimaryDefaultLoad(1383778705)
                                        .withSecondaryDefaultLoad(2040328424)
                                        .withDefaultLoad(431399757),
                                    new ServiceLoadMetricDescription()
                                        .withName("ndlkzgxhurip")
                                        .withWeight(ServiceLoadMetricWeight.LOW)
                                        .withPrimaryDefaultLoad(1784018500)
                                        .withSecondaryDefaultLoad(1806634279)
                                        .withDefaultLoad(2086660215)))
                        .withServicePlacementPolicies(
                            Arrays
                                .asList(
                                    new ServicePlacementPolicyDescription(),
                                    new ServicePlacementPolicyDescription(),
                                    new ServicePlacementPolicyDescription()))
                        .withDefaultMoveCost(MoveCost.HIGH)
                        .withServiceTypeName("tshhszhedp")
                        .withPartitionDescription(new PartitionSchemeDescription())
                        .withServicePackageActivationMode(ArmServicePackageActivationMode.EXCLUSIVE_PROCESS)
                        .withServiceDnsName("ubmwmbesld"))
                .withLocation("ubyyntw")
                .withTags(
                    mapOf(
                        "otgqrlltmu",
                        "qtkoievs",
                        "zmuvpbttdumorppx",
                        "lauwzizxbmpgcjef",
                        "fgohdneuelfphs",
                        "bmnzbtbhjpgl",
                        "v",
                        "yhtozfikdowwqu"));
        model = BinaryData.fromObject(model).toObject(ServiceResourceInner.class);
        Assertions.assertEquals("wwtppj", model.properties().placementConstraints());
        Assertions
            .assertEquals(
                ServiceCorrelationScheme.NON_ALIGNED_AFFINITY, model.properties().correlationScheme().get(0).scheme());
        Assertions.assertEquals("ogaok", model.properties().correlationScheme().get(0).serviceName());
        Assertions.assertEquals("mhhv", model.properties().serviceLoadMetrics().get(0).name());
        Assertions.assertEquals(ServiceLoadMetricWeight.ZERO, model.properties().serviceLoadMetrics().get(0).weight());
        Assertions.assertEquals(243631399, model.properties().serviceLoadMetrics().get(0).primaryDefaultLoad());
        Assertions.assertEquals(191107441, model.properties().serviceLoadMetrics().get(0).secondaryDefaultLoad());
        Assertions.assertEquals(1245356368, model.properties().serviceLoadMetrics().get(0).defaultLoad());
        Assertions.assertEquals(MoveCost.HIGH, model.properties().defaultMoveCost());
        Assertions.assertEquals("tshhszhedp", model.properties().serviceTypeName());
        Assertions
            .assertEquals(
                ArmServicePackageActivationMode.EXCLUSIVE_PROCESS, model.properties().servicePackageActivationMode());
        Assertions.assertEquals("ubmwmbesld", model.properties().serviceDnsName());
        Assertions.assertEquals("ubyyntw", model.location());
        Assertions.assertEquals("qtkoievs", model.tags().get("otgqrlltmu"));
    }

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