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

package com.azure.resourcemanager.desktopvirtualization.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.desktopvirtualization.models.ScalingHostPoolReference;
import com.azure.resourcemanager.desktopvirtualization.models.ScalingPlanPatch;
import com.azure.resourcemanager.desktopvirtualization.models.ScalingSchedule;
import com.azure.resourcemanager.desktopvirtualization.models.SessionHostLoadBalancingAlgorithm;
import com.azure.resourcemanager.desktopvirtualization.models.StopHostsWhen;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ScalingPlanPatchTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ScalingPlanPatch model =
            BinaryData
                .fromString(
                    "{\"tags\":{\"xzdmohctb\":\"bavo\",\"ndnvo\":\"vudwx\",\"lazjdyggdtjixhbk\":\"gujjugwdkcglh\"},\"properties\":{\"description\":\"qweykhmenev\",\"friendlyName\":\"exfwhy\",\"timeZone\":\"i\",\"exclusionTag\":\"yvdcsitynnaa\",\"schedules\":[{\"name\":\"tehfiqscjeypvh\",\"daysOfWeek\":[],\"rampUpLoadBalancingAlgorithm\":\"DepthFirst\",\"rampUpMinimumHostsPct\":693587344,\"rampUpCapacityThresholdPct\":1290040732,\"peakLoadBalancingAlgorithm\":\"DepthFirst\",\"rampDownLoadBalancingAlgorithm\":\"BreadthFirst\",\"rampDownMinimumHostsPct\":509090660,\"rampDownCapacityThresholdPct\":545322213,\"rampDownForceLogoffUsers\":true,\"rampDownStopHostsWhen\":\"ZeroSessions\",\"rampDownWaitTimeMinutes\":1069395538,\"rampDownNotificationMessage\":\"qjpkcattpngjcrc\",\"offPeakLoadBalancingAlgorithm\":\"BreadthFirst\"},{\"name\":\"jh\",\"daysOfWeek\":[],\"rampUpLoadBalancingAlgorithm\":\"DepthFirst\",\"rampUpMinimumHostsPct\":1964386727,\"rampUpCapacityThresholdPct\":1223642392,\"peakLoadBalancingAlgorithm\":\"DepthFirst\",\"rampDownLoadBalancingAlgorithm\":\"DepthFirst\",\"rampDownMinimumHostsPct\":904416760,\"rampDownCapacityThresholdPct\":389510865,\"rampDownForceLogoffUsers\":false,\"rampDownStopHostsWhen\":\"ZeroActiveSessions\",\"rampDownWaitTimeMinutes\":1111397810,\"rampDownNotificationMessage\":\"ltrpmopj\",\"offPeakLoadBalancingAlgorithm\":\"DepthFirst\"}],\"hostPoolReferences\":[{\"hostPoolArmPath\":\"kthfui\",\"scalingPlanEnabled\":true}]}}")
                .toObject(ScalingPlanPatch.class);
        Assertions.assertEquals("bavo", model.tags().get("xzdmohctb"));
        Assertions.assertEquals("qweykhmenev", model.description());
        Assertions.assertEquals("exfwhy", model.friendlyName());
        Assertions.assertEquals("i", model.timeZone());
        Assertions.assertEquals("yvdcsitynnaa", model.exclusionTag());
        Assertions.assertEquals("tehfiqscjeypvh", model.schedules().get(0).name());
        Assertions
            .assertEquals(
                SessionHostLoadBalancingAlgorithm.DEPTH_FIRST, model.schedules().get(0).rampUpLoadBalancingAlgorithm());
        Assertions.assertEquals(693587344, model.schedules().get(0).rampUpMinimumHostsPct());
        Assertions.assertEquals(1290040732, model.schedules().get(0).rampUpCapacityThresholdPct());
        Assertions
            .assertEquals(
                SessionHostLoadBalancingAlgorithm.DEPTH_FIRST, model.schedules().get(0).peakLoadBalancingAlgorithm());
        Assertions
            .assertEquals(
                SessionHostLoadBalancingAlgorithm.BREADTH_FIRST,
                model.schedules().get(0).rampDownLoadBalancingAlgorithm());
        Assertions.assertEquals(509090660, model.schedules().get(0).rampDownMinimumHostsPct());
        Assertions.assertEquals(545322213, model.schedules().get(0).rampDownCapacityThresholdPct());
        Assertions.assertEquals(true, model.schedules().get(0).rampDownForceLogoffUsers());
        Assertions.assertEquals(StopHostsWhen.ZERO_SESSIONS, model.schedules().get(0).rampDownStopHostsWhen());
        Assertions.assertEquals(1069395538, model.schedules().get(0).rampDownWaitTimeMinutes());
        Assertions.assertEquals("qjpkcattpngjcrc", model.schedules().get(0).rampDownNotificationMessage());
        Assertions
            .assertEquals(
                SessionHostLoadBalancingAlgorithm.BREADTH_FIRST,
                model.schedules().get(0).offPeakLoadBalancingAlgorithm());
        Assertions.assertEquals("kthfui", model.hostPoolReferences().get(0).hostPoolArmPath());
        Assertions.assertEquals(true, model.hostPoolReferences().get(0).scalingPlanEnabled());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ScalingPlanPatch model =
            new ScalingPlanPatch()
                .withTags(mapOf("xzdmohctb", "bavo", "ndnvo", "vudwx", "lazjdyggdtjixhbk", "gujjugwdkcglh"))
                .withDescription("qweykhmenev")
                .withFriendlyName("exfwhy")
                .withTimeZone("i")
                .withExclusionTag("yvdcsitynnaa")
                .withSchedules(
                    Arrays
                        .asList(
                            new ScalingSchedule()
                                .withName("tehfiqscjeypvh")
                                .withDaysOfWeek(Arrays.asList())
                                .withRampUpLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.DEPTH_FIRST)
                                .withRampUpMinimumHostsPct(693587344)
                                .withRampUpCapacityThresholdPct(1290040732)
                                .withPeakLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.DEPTH_FIRST)
                                .withRampDownLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.BREADTH_FIRST)
                                .withRampDownMinimumHostsPct(509090660)
                                .withRampDownCapacityThresholdPct(545322213)
                                .withRampDownForceLogoffUsers(true)
                                .withRampDownStopHostsWhen(StopHostsWhen.ZERO_SESSIONS)
                                .withRampDownWaitTimeMinutes(1069395538)
                                .withRampDownNotificationMessage("qjpkcattpngjcrc")
                                .withOffPeakLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.BREADTH_FIRST),
                            new ScalingSchedule()
                                .withName("jh")
                                .withDaysOfWeek(Arrays.asList())
                                .withRampUpLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.DEPTH_FIRST)
                                .withRampUpMinimumHostsPct(1964386727)
                                .withRampUpCapacityThresholdPct(1223642392)
                                .withPeakLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.DEPTH_FIRST)
                                .withRampDownLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.DEPTH_FIRST)
                                .withRampDownMinimumHostsPct(904416760)
                                .withRampDownCapacityThresholdPct(389510865)
                                .withRampDownForceLogoffUsers(false)
                                .withRampDownStopHostsWhen(StopHostsWhen.ZERO_ACTIVE_SESSIONS)
                                .withRampDownWaitTimeMinutes(1111397810)
                                .withRampDownNotificationMessage("ltrpmopj")
                                .withOffPeakLoadBalancingAlgorithm(SessionHostLoadBalancingAlgorithm.DEPTH_FIRST)))
                .withHostPoolReferences(
                    Arrays
                        .asList(
                            new ScalingHostPoolReference().withHostPoolArmPath("kthfui").withScalingPlanEnabled(true)));
        model = BinaryData.fromObject(model).toObject(ScalingPlanPatch.class);
        Assertions.assertEquals("bavo", model.tags().get("xzdmohctb"));
        Assertions.assertEquals("qweykhmenev", model.description());
        Assertions.assertEquals("exfwhy", model.friendlyName());
        Assertions.assertEquals("i", model.timeZone());
        Assertions.assertEquals("yvdcsitynnaa", model.exclusionTag());
        Assertions.assertEquals("tehfiqscjeypvh", model.schedules().get(0).name());
        Assertions
            .assertEquals(
                SessionHostLoadBalancingAlgorithm.DEPTH_FIRST, model.schedules().get(0).rampUpLoadBalancingAlgorithm());
        Assertions.assertEquals(693587344, model.schedules().get(0).rampUpMinimumHostsPct());
        Assertions.assertEquals(1290040732, model.schedules().get(0).rampUpCapacityThresholdPct());
        Assertions
            .assertEquals(
                SessionHostLoadBalancingAlgorithm.DEPTH_FIRST, model.schedules().get(0).peakLoadBalancingAlgorithm());
        Assertions
            .assertEquals(
                SessionHostLoadBalancingAlgorithm.BREADTH_FIRST,
                model.schedules().get(0).rampDownLoadBalancingAlgorithm());
        Assertions.assertEquals(509090660, model.schedules().get(0).rampDownMinimumHostsPct());
        Assertions.assertEquals(545322213, model.schedules().get(0).rampDownCapacityThresholdPct());
        Assertions.assertEquals(true, model.schedules().get(0).rampDownForceLogoffUsers());
        Assertions.assertEquals(StopHostsWhen.ZERO_SESSIONS, model.schedules().get(0).rampDownStopHostsWhen());
        Assertions.assertEquals(1069395538, model.schedules().get(0).rampDownWaitTimeMinutes());
        Assertions.assertEquals("qjpkcattpngjcrc", model.schedules().get(0).rampDownNotificationMessage());
        Assertions
            .assertEquals(
                SessionHostLoadBalancingAlgorithm.BREADTH_FIRST,
                model.schedules().get(0).offPeakLoadBalancingAlgorithm());
        Assertions.assertEquals("kthfui", model.hostPoolReferences().get(0).hostPoolArmPath());
        Assertions.assertEquals(true, model.hostPoolReferences().get(0).scalingPlanEnabled());
    }

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