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

package com.azure.resourcemanager.recoveryservicesbackup.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.recoveryservicesbackup.fluent.models.BackupEngineBaseResourceInner;
import com.azure.resourcemanager.recoveryservicesbackup.models.BackupEngineBase;
import com.azure.resourcemanager.recoveryservicesbackup.models.BackupEngineExtendedInfo;
import com.azure.resourcemanager.recoveryservicesbackup.models.BackupManagementType;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class BackupEngineBaseResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        BackupEngineBaseResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"backupEngineType\":\"BackupEngineBase\",\"friendlyName\":\"xcxrsl\",\"backupManagementType\":\"AzureWorkload\",\"registrationStatus\":\"wuoegrpk\",\"backupEngineState\":\"wniyqsluicpd\",\"healthStatus\":\"kzzlvmbmpaxmodf\",\"canReRegister\":false,\"backupEngineId\":\"yw\",\"dpmVersion\":\"pfvmwyhrfou\",\"azureBackupAgentVersion\":\"taakc\",\"isAzureBackupAgentUpgradeAvailable\":true,\"isDpmUpgradeAvailable\":true,\"extendedInfo\":{\"databaseName\":\"tmnubexkpzksmon\",\"protectedItemsCount\":1929847054,\"protectedServersCount\":1598005613,\"diskCount\":1083170526,\"usedDiskSpace\":81.92468371755585,\"availableDiskSpace\":99.15207166693078,\"refreshedAt\":\"2021-01-25T05:21:40Z\",\"azureProtectedInstances\":1364703724}},\"eTag\":\"ojvpa\",\"location\":\"qgxy\",\"tags\":{\"xozap\":\"cmbqfqvmk\",\"dd\":\"helxprglya\",\"rjxgciqib\":\"kcbcue\",\"sdqrhzoymibmrq\":\"hos\"},\"id\":\"ibahwflus\",\"name\":\"dtmhrkwofyyvoqa\",\"type\":\"piexpbtgiw\"}")
                .toObject(BackupEngineBaseResourceInner.class);
        Assertions.assertEquals("qgxy", model.location());
        Assertions.assertEquals("cmbqfqvmk", model.tags().get("xozap"));
        Assertions.assertEquals("xcxrsl", model.properties().friendlyName());
        Assertions.assertEquals(BackupManagementType.AZURE_WORKLOAD, model.properties().backupManagementType());
        Assertions.assertEquals("wuoegrpk", model.properties().registrationStatus());
        Assertions.assertEquals("wniyqsluicpd", model.properties().backupEngineState());
        Assertions.assertEquals("kzzlvmbmpaxmodf", model.properties().healthStatus());
        Assertions.assertEquals(false, model.properties().canReRegister());
        Assertions.assertEquals("yw", model.properties().backupEngineId());
        Assertions.assertEquals("pfvmwyhrfou", model.properties().dpmVersion());
        Assertions.assertEquals("taakc", model.properties().azureBackupAgentVersion());
        Assertions.assertEquals(true, model.properties().isAzureBackupAgentUpgradeAvailable());
        Assertions.assertEquals(true, model.properties().isDpmUpgradeAvailable());
        Assertions.assertEquals("tmnubexkpzksmon", model.properties().extendedInfo().databaseName());
        Assertions.assertEquals(1929847054, model.properties().extendedInfo().protectedItemsCount());
        Assertions.assertEquals(1598005613, model.properties().extendedInfo().protectedServersCount());
        Assertions.assertEquals(1083170526, model.properties().extendedInfo().diskCount());
        Assertions.assertEquals(81.92468371755585D, model.properties().extendedInfo().usedDiskSpace());
        Assertions.assertEquals(99.15207166693078D, model.properties().extendedInfo().availableDiskSpace());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-01-25T05:21:40Z"), model.properties().extendedInfo().refreshedAt());
        Assertions.assertEquals(1364703724, model.properties().extendedInfo().azureProtectedInstances());
        Assertions.assertEquals("ojvpa", model.etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        BackupEngineBaseResourceInner model =
            new BackupEngineBaseResourceInner()
                .withLocation("qgxy")
                .withTags(
                    mapOf("xozap", "cmbqfqvmk", "dd", "helxprglya", "rjxgciqib", "kcbcue", "sdqrhzoymibmrq", "hos"))
                .withProperties(
                    new BackupEngineBase()
                        .withFriendlyName("xcxrsl")
                        .withBackupManagementType(BackupManagementType.AZURE_WORKLOAD)
                        .withRegistrationStatus("wuoegrpk")
                        .withBackupEngineState("wniyqsluicpd")
                        .withHealthStatus("kzzlvmbmpaxmodf")
                        .withCanReRegister(false)
                        .withBackupEngineId("yw")
                        .withDpmVersion("pfvmwyhrfou")
                        .withAzureBackupAgentVersion("taakc")
                        .withIsAzureBackupAgentUpgradeAvailable(true)
                        .withIsDpmUpgradeAvailable(true)
                        .withExtendedInfo(
                            new BackupEngineExtendedInfo()
                                .withDatabaseName("tmnubexkpzksmon")
                                .withProtectedItemsCount(1929847054)
                                .withProtectedServersCount(1598005613)
                                .withDiskCount(1083170526)
                                .withUsedDiskSpace(81.92468371755585D)
                                .withAvailableDiskSpace(99.15207166693078D)
                                .withRefreshedAt(OffsetDateTime.parse("2021-01-25T05:21:40Z"))
                                .withAzureProtectedInstances(1364703724)))
                .withEtag("ojvpa");
        model = BinaryData.fromObject(model).toObject(BackupEngineBaseResourceInner.class);
        Assertions.assertEquals("qgxy", model.location());
        Assertions.assertEquals("cmbqfqvmk", model.tags().get("xozap"));
        Assertions.assertEquals("xcxrsl", model.properties().friendlyName());
        Assertions.assertEquals(BackupManagementType.AZURE_WORKLOAD, model.properties().backupManagementType());
        Assertions.assertEquals("wuoegrpk", model.properties().registrationStatus());
        Assertions.assertEquals("wniyqsluicpd", model.properties().backupEngineState());
        Assertions.assertEquals("kzzlvmbmpaxmodf", model.properties().healthStatus());
        Assertions.assertEquals(false, model.properties().canReRegister());
        Assertions.assertEquals("yw", model.properties().backupEngineId());
        Assertions.assertEquals("pfvmwyhrfou", model.properties().dpmVersion());
        Assertions.assertEquals("taakc", model.properties().azureBackupAgentVersion());
        Assertions.assertEquals(true, model.properties().isAzureBackupAgentUpgradeAvailable());
        Assertions.assertEquals(true, model.properties().isDpmUpgradeAvailable());
        Assertions.assertEquals("tmnubexkpzksmon", model.properties().extendedInfo().databaseName());
        Assertions.assertEquals(1929847054, model.properties().extendedInfo().protectedItemsCount());
        Assertions.assertEquals(1598005613, model.properties().extendedInfo().protectedServersCount());
        Assertions.assertEquals(1083170526, model.properties().extendedInfo().diskCount());
        Assertions.assertEquals(81.92468371755585D, model.properties().extendedInfo().usedDiskSpace());
        Assertions.assertEquals(99.15207166693078D, model.properties().extendedInfo().availableDiskSpace());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-01-25T05:21:40Z"), model.properties().extendedInfo().refreshedAt());
        Assertions.assertEquals(1364703724, model.properties().extendedInfo().azureProtectedInstances());
        Assertions.assertEquals("ojvpa", model.etag());
    }

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