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

package com.azure.resourcemanager.devcenter.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.devcenter.models.ScheduleEnableStatus;
import com.azure.resourcemanager.devcenter.models.ScheduleUpdate;
import com.azure.resourcemanager.devcenter.models.ScheduledFrequency;
import com.azure.resourcemanager.devcenter.models.ScheduledType;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ScheduleUpdateTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ScheduleUpdate model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"type\":\"StopDevBox\",\"frequency\":\"Daily\",\"time\":\"vdkcrodtj\",\"timeZone\":\"fw\",\"state\":\"Enabled\"},\"tags\":{\"kggkfpa\":\"kacjvefkdlfo\",\"pulpqblylsyxk\":\"ao\"},\"location\":\"nsj\"}")
                .toObject(ScheduleUpdate.class);
        Assertions.assertEquals("kacjvefkdlfo", model.tags().get("kggkfpa"));
        Assertions.assertEquals("nsj", model.location());
        Assertions.assertEquals(ScheduledType.STOP_DEV_BOX, model.type());
        Assertions.assertEquals(ScheduledFrequency.DAILY, model.frequency());
        Assertions.assertEquals("vdkcrodtj", model.time());
        Assertions.assertEquals("fw", model.timeZone());
        Assertions.assertEquals(ScheduleEnableStatus.ENABLED, model.state());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ScheduleUpdate model =
            new ScheduleUpdate()
                .withTags(mapOf("kggkfpa", "kacjvefkdlfo", "pulpqblylsyxk", "ao"))
                .withLocation("nsj")
                .withType(ScheduledType.STOP_DEV_BOX)
                .withFrequency(ScheduledFrequency.DAILY)
                .withTime("vdkcrodtj")
                .withTimeZone("fw")
                .withState(ScheduleEnableStatus.ENABLED);
        model = BinaryData.fromObject(model).toObject(ScheduleUpdate.class);
        Assertions.assertEquals("kacjvefkdlfo", model.tags().get("kggkfpa"));
        Assertions.assertEquals("nsj", model.location());
        Assertions.assertEquals(ScheduledType.STOP_DEV_BOX, model.type());
        Assertions.assertEquals(ScheduledFrequency.DAILY, model.frequency());
        Assertions.assertEquals("vdkcrodtj", model.time());
        Assertions.assertEquals("fw", model.timeZone());
        Assertions.assertEquals(ScheduleEnableStatus.ENABLED, model.state());
    }

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