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

package com.azure.resourcemanager.appcontainers.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.appcontainers.models.CustomScaleRule;
import com.azure.resourcemanager.appcontainers.models.HttpScaleRule;
import com.azure.resourcemanager.appcontainers.models.QueueScaleRule;
import com.azure.resourcemanager.appcontainers.models.Scale;
import com.azure.resourcemanager.appcontainers.models.ScaleRule;
import com.azure.resourcemanager.appcontainers.models.TcpScaleRule;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ScaleTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        Scale model =
            BinaryData
                .fromString(
                    "{\"minReplicas\":1591182394,\"maxReplicas\":235845887,\"rules\":[{\"name\":\"utncorm\",\"azureQueue\":{\"queueName\":\"qtvcofudflvkgj\",\"queueLength\":1622767746,\"auth\":[]},\"custom\":{\"type\":\"nqvsaznqnto\",\"metadata\":{},\"auth\":[]},\"http\":{\"metadata\":{},\"auth\":[]},\"tcp\":{\"metadata\":{},\"auth\":[]}},{\"name\":\"yc\",\"azureQueue\":{\"queueName\":\"uwjuetaeburuvdmo\",\"queueLength\":293180976,\"auth\":[]},\"custom\":{\"type\":\"wabm\",\"metadata\":{},\"auth\":[]},\"http\":{\"metadata\":{},\"auth\":[]},\"tcp\":{\"metadata\":{},\"auth\":[]}}]}")
                .toObject(Scale.class);
        Assertions.assertEquals(1591182394, model.minReplicas());
        Assertions.assertEquals(235845887, model.maxReplicas());
        Assertions.assertEquals("utncorm", model.rules().get(0).name());
        Assertions.assertEquals("qtvcofudflvkgj", model.rules().get(0).azureQueue().queueName());
        Assertions.assertEquals(1622767746, model.rules().get(0).azureQueue().queueLength());
        Assertions.assertEquals("nqvsaznqnto", model.rules().get(0).custom().type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        Scale model =
            new Scale()
                .withMinReplicas(1591182394)
                .withMaxReplicas(235845887)
                .withRules(
                    Arrays
                        .asList(
                            new ScaleRule()
                                .withName("utncorm")
                                .withAzureQueue(
                                    new QueueScaleRule()
                                        .withQueueName("qtvcofudflvkgj")
                                        .withQueueLength(1622767746)
                                        .withAuth(Arrays.asList()))
                                .withCustom(
                                    new CustomScaleRule()
                                        .withType("nqvsaznqnto")
                                        .withMetadata(mapOf())
                                        .withAuth(Arrays.asList()))
                                .withHttp(new HttpScaleRule().withMetadata(mapOf()).withAuth(Arrays.asList()))
                                .withTcp(new TcpScaleRule().withMetadata(mapOf()).withAuth(Arrays.asList())),
                            new ScaleRule()
                                .withName("yc")
                                .withAzureQueue(
                                    new QueueScaleRule()
                                        .withQueueName("uwjuetaeburuvdmo")
                                        .withQueueLength(293180976)
                                        .withAuth(Arrays.asList()))
                                .withCustom(
                                    new CustomScaleRule()
                                        .withType("wabm")
                                        .withMetadata(mapOf())
                                        .withAuth(Arrays.asList()))
                                .withHttp(new HttpScaleRule().withMetadata(mapOf()).withAuth(Arrays.asList()))
                                .withTcp(new TcpScaleRule().withMetadata(mapOf()).withAuth(Arrays.asList()))));
        model = BinaryData.fromObject(model).toObject(Scale.class);
        Assertions.assertEquals(1591182394, model.minReplicas());
        Assertions.assertEquals(235845887, model.maxReplicas());
        Assertions.assertEquals("utncorm", model.rules().get(0).name());
        Assertions.assertEquals("qtvcofudflvkgj", model.rules().get(0).azureQueue().queueName());
        Assertions.assertEquals(1622767746, model.rules().get(0).azureQueue().queueLength());
        Assertions.assertEquals("nqvsaznqnto", model.rules().get(0).custom().type());
    }

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