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

package com.azure.resourcemanager.devtestlabs.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.devtestlabs.fluent.models.LabProperties;
import com.azure.resourcemanager.devtestlabs.models.EnableStatus;
import com.azure.resourcemanager.devtestlabs.models.EnvironmentPermission;
import com.azure.resourcemanager.devtestlabs.models.LabAnnouncementProperties;
import com.azure.resourcemanager.devtestlabs.models.LabSupportProperties;
import com.azure.resourcemanager.devtestlabs.models.PremiumDataDisk;
import com.azure.resourcemanager.devtestlabs.models.StorageType;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class LabPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        LabProperties model =
            BinaryData
                .fromString(
                    "{\"defaultStorageAccount\":\"ypyqrimzinp\",\"defaultPremiumStorageAccount\":\"wjdk\",\"artifactsStorageAccount\":\"soodqxhcrmnoh\",\"premiumDataDiskStorageAccount\":\"ckwhds\",\"vaultName\":\"fiyipjxsqwpgrj\",\"labStorageType\":\"Premium\",\"mandatoryArtifactsResourceIdsLinux\":[\"cjxvsnbyxqab\",\"mocpc\",\"shurzafbljjgpbto\",\"c\"],\"mandatoryArtifactsResourceIdsWindows\":[\"ljavbqid\"],\"createdDate\":\"2021-05-31T14:07:02Z\",\"premiumDataDisks\":\"Disabled\",\"environmentPermission\":\"Contributor\",\"announcement\":{\"title\":\"kudjkrlkhb\",\"markdown\":\"fepgzgq\",\"enabled\":\"Enabled\",\"expirationDate\":\"2021-02-26T10:43:13Z\",\"expired\":true,\"provisioningState\":\"c\",\"uniqueIdentifier\":\"ierhhbcsglummaj\"},\"support\":{\"enabled\":\"Disabled\",\"markdown\":\"xobnbdxkqpxok\"},\"vmCreationResourceGroup\":\"ionpimexg\",\"publicIpId\":\"xgcp\",\"loadBalancerId\":\"gmaajrm\",\"networkSecurityGroupId\":\"jwzrl\",\"extendedProperties\":{\"qsqsy\":\"clwhijcoejctbz\"},\"provisioningState\":\"kbfkg\",\"uniqueIdentifier\":\"dkexxppofm\"}")
                .toObject(LabProperties.class);
        Assertions.assertEquals(StorageType.PREMIUM, model.labStorageType());
        Assertions.assertEquals("cjxvsnbyxqab", model.mandatoryArtifactsResourceIdsLinux().get(0));
        Assertions.assertEquals("ljavbqid", model.mandatoryArtifactsResourceIdsWindows().get(0));
        Assertions.assertEquals(PremiumDataDisk.DISABLED, model.premiumDataDisks());
        Assertions.assertEquals(EnvironmentPermission.CONTRIBUTOR, model.environmentPermission());
        Assertions.assertEquals("kudjkrlkhb", model.announcement().title());
        Assertions.assertEquals("fepgzgq", model.announcement().markdown());
        Assertions.assertEquals(EnableStatus.ENABLED, model.announcement().enabled());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-26T10:43:13Z"), model.announcement().expirationDate());
        Assertions.assertEquals(true, model.announcement().expired());
        Assertions.assertEquals(EnableStatus.DISABLED, model.support().enabled());
        Assertions.assertEquals("xobnbdxkqpxok", model.support().markdown());
        Assertions.assertEquals("clwhijcoejctbz", model.extendedProperties().get("qsqsy"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        LabProperties model =
            new LabProperties()
                .withLabStorageType(StorageType.PREMIUM)
                .withMandatoryArtifactsResourceIdsLinux(Arrays.asList("cjxvsnbyxqab", "mocpc", "shurzafbljjgpbto", "c"))
                .withMandatoryArtifactsResourceIdsWindows(Arrays.asList("ljavbqid"))
                .withPremiumDataDisks(PremiumDataDisk.DISABLED)
                .withEnvironmentPermission(EnvironmentPermission.CONTRIBUTOR)
                .withAnnouncement(
                    new LabAnnouncementProperties()
                        .withTitle("kudjkrlkhb")
                        .withMarkdown("fepgzgq")
                        .withEnabled(EnableStatus.ENABLED)
                        .withExpirationDate(OffsetDateTime.parse("2021-02-26T10:43:13Z"))
                        .withExpired(true))
                .withSupport(
                    new LabSupportProperties().withEnabled(EnableStatus.DISABLED).withMarkdown("xobnbdxkqpxok"))
                .withExtendedProperties(mapOf("qsqsy", "clwhijcoejctbz"));
        model = BinaryData.fromObject(model).toObject(LabProperties.class);
        Assertions.assertEquals(StorageType.PREMIUM, model.labStorageType());
        Assertions.assertEquals("cjxvsnbyxqab", model.mandatoryArtifactsResourceIdsLinux().get(0));
        Assertions.assertEquals("ljavbqid", model.mandatoryArtifactsResourceIdsWindows().get(0));
        Assertions.assertEquals(PremiumDataDisk.DISABLED, model.premiumDataDisks());
        Assertions.assertEquals(EnvironmentPermission.CONTRIBUTOR, model.environmentPermission());
        Assertions.assertEquals("kudjkrlkhb", model.announcement().title());
        Assertions.assertEquals("fepgzgq", model.announcement().markdown());
        Assertions.assertEquals(EnableStatus.ENABLED, model.announcement().enabled());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-26T10:43:13Z"), model.announcement().expirationDate());
        Assertions.assertEquals(true, model.announcement().expired());
        Assertions.assertEquals(EnableStatus.DISABLED, model.support().enabled());
        Assertions.assertEquals("xobnbdxkqpxok", model.support().markdown());
        Assertions.assertEquals("clwhijcoejctbz", model.extendedProperties().get("qsqsy"));
    }

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