// 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.models.AzureFileshareProtectedItem;
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureFileshareProtectedItemExtendedInfo;
import com.azure.resourcemanager.recoveryservicesbackup.models.CreateMode;
import com.azure.resourcemanager.recoveryservicesbackup.models.KpiResourceHealthDetails;
import com.azure.resourcemanager.recoveryservicesbackup.models.ProtectionState;
import com.azure.resourcemanager.recoveryservicesbackup.models.ResourceHealthStatus;
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 AzureFileshareProtectedItemTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureFileshareProtectedItem model =
            BinaryData
                .fromString(
                    "{\"protectedItemType\":\"AzureFileShareProtectedItem\",\"friendlyName\":\"xtqmieoxor\",\"protectionStatus\":\"ufhyaomtbgh\",\"protectionState\":\"ProtectionPaused\",\"lastBackupStatus\":\"rvk\",\"lastBackupTime\":\"2021-11-21T11:52:27Z\",\"kpisHealths\":{\"bibgjmfxumv\":{\"resourceHealthStatus\":\"TransientUnhealthy\",\"resourceHealthDetails\":[]},\"ovwxnbkfezzxsc\":{\"resourceHealthStatus\":\"PersistentDegraded\",\"resourceHealthDetails\":[]},\"g\":{\"resourceHealthStatus\":\"Invalid\",\"resourceHealthDetails\":[]},\"zbomvzzbtdcqvpni\":{\"resourceHealthStatus\":\"TransientDegraded\",\"resourceHealthDetails\":[]}},\"extendedInfo\":{\"oldestRecoveryPoint\":\"2021-07-28T02:37:45Z\",\"recoveryPointCount\":277819924,\"policyState\":\"wdsh\",\"resourceState\":\"snrbgyefrymsgao\",\"resourceStateSyncTime\":\"2020-12-25T11:28:29Z\"},\"backupManagementType\":\"AzureBackupServer\",\"workloadType\":\"VMwareVM\",\"containerName\":\"mrfhirctymox\",\"sourceResourceId\":\"tpipiwyczuhx\",\"policyId\":\"pqjlihhyusps\",\"lastRecoveryPoint\":\"2021-06-21T18:35:02Z\",\"backupSetName\":\"vlmfwdgzxulucv\",\"createMode\":\"Recover\",\"deferredDeleteTimeInUTC\":\"2021-10-14T22:40:57Z\",\"isScheduledForDeferredDelete\":false,\"deferredDeleteTimeRemaining\":\"zvxurisjnhny\",\"isDeferredDeleteScheduleUpcoming\":false,\"isRehydrate\":true,\"resourceGuardOperationRequests\":[\"gxmrhublwp\",\"esutrgjupauutpw\"],\"isArchiveEnabled\":true,\"policyName\":\"hej\",\"softDeleteRetentionPeriod\":248529956}")
                .toObject(AzureFileshareProtectedItem.class);
        Assertions.assertEquals("mrfhirctymox", model.containerName());
        Assertions.assertEquals("tpipiwyczuhx", model.sourceResourceId());
        Assertions.assertEquals("pqjlihhyusps", model.policyId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-21T18:35:02Z"), model.lastRecoveryPoint());
        Assertions.assertEquals("vlmfwdgzxulucv", model.backupSetName());
        Assertions.assertEquals(CreateMode.RECOVER, model.createMode());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-14T22:40:57Z"), model.deferredDeleteTimeInUtc());
        Assertions.assertEquals(false, model.isScheduledForDeferredDelete());
        Assertions.assertEquals("zvxurisjnhny", model.deferredDeleteTimeRemaining());
        Assertions.assertEquals(false, model.isDeferredDeleteScheduleUpcoming());
        Assertions.assertEquals(true, model.isRehydrate());
        Assertions.assertEquals("gxmrhublwp", model.resourceGuardOperationRequests().get(0));
        Assertions.assertEquals(true, model.isArchiveEnabled());
        Assertions.assertEquals("hej", model.policyName());
        Assertions.assertEquals(248529956, model.softDeleteRetentionPeriod());
        Assertions.assertEquals("xtqmieoxor", model.friendlyName());
        Assertions.assertEquals("ufhyaomtbgh", model.protectionStatus());
        Assertions.assertEquals(ProtectionState.PROTECTION_PAUSED, model.protectionState());
        Assertions.assertEquals("rvk", model.lastBackupStatus());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-21T11:52:27Z"), model.lastBackupTime());
        Assertions
            .assertEquals(
                ResourceHealthStatus.TRANSIENT_UNHEALTHY,
                model.kpisHealths().get("bibgjmfxumv").resourceHealthStatus());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-07-28T02:37:45Z"), model.extendedInfo().oldestRecoveryPoint());
        Assertions.assertEquals(277819924, model.extendedInfo().recoveryPointCount());
        Assertions.assertEquals("wdsh", model.extendedInfo().policyState());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureFileshareProtectedItem model =
            new AzureFileshareProtectedItem()
                .withContainerName("mrfhirctymox")
                .withSourceResourceId("tpipiwyczuhx")
                .withPolicyId("pqjlihhyusps")
                .withLastRecoveryPoint(OffsetDateTime.parse("2021-06-21T18:35:02Z"))
                .withBackupSetName("vlmfwdgzxulucv")
                .withCreateMode(CreateMode.RECOVER)
                .withDeferredDeleteTimeInUtc(OffsetDateTime.parse("2021-10-14T22:40:57Z"))
                .withIsScheduledForDeferredDelete(false)
                .withDeferredDeleteTimeRemaining("zvxurisjnhny")
                .withIsDeferredDeleteScheduleUpcoming(false)
                .withIsRehydrate(true)
                .withResourceGuardOperationRequests(Arrays.asList("gxmrhublwp", "esutrgjupauutpw"))
                .withIsArchiveEnabled(true)
                .withPolicyName("hej")
                .withSoftDeleteRetentionPeriod(248529956)
                .withFriendlyName("xtqmieoxor")
                .withProtectionStatus("ufhyaomtbgh")
                .withProtectionState(ProtectionState.PROTECTION_PAUSED)
                .withLastBackupStatus("rvk")
                .withLastBackupTime(OffsetDateTime.parse("2021-11-21T11:52:27Z"))
                .withKpisHealths(
                    mapOf(
                        "bibgjmfxumv",
                        new KpiResourceHealthDetails()
                            .withResourceHealthStatus(ResourceHealthStatus.TRANSIENT_UNHEALTHY)
                            .withResourceHealthDetails(Arrays.asList()),
                        "ovwxnbkfezzxsc",
                        new KpiResourceHealthDetails()
                            .withResourceHealthStatus(ResourceHealthStatus.PERSISTENT_DEGRADED)
                            .withResourceHealthDetails(Arrays.asList()),
                        "g",
                        new KpiResourceHealthDetails()
                            .withResourceHealthStatus(ResourceHealthStatus.INVALID)
                            .withResourceHealthDetails(Arrays.asList()),
                        "zbomvzzbtdcqvpni",
                        new KpiResourceHealthDetails()
                            .withResourceHealthStatus(ResourceHealthStatus.TRANSIENT_DEGRADED)
                            .withResourceHealthDetails(Arrays.asList())))
                .withExtendedInfo(
                    new AzureFileshareProtectedItemExtendedInfo()
                        .withOldestRecoveryPoint(OffsetDateTime.parse("2021-07-28T02:37:45Z"))
                        .withRecoveryPointCount(277819924)
                        .withPolicyState("wdsh"));
        model = BinaryData.fromObject(model).toObject(AzureFileshareProtectedItem.class);
        Assertions.assertEquals("mrfhirctymox", model.containerName());
        Assertions.assertEquals("tpipiwyczuhx", model.sourceResourceId());
        Assertions.assertEquals("pqjlihhyusps", model.policyId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-21T18:35:02Z"), model.lastRecoveryPoint());
        Assertions.assertEquals("vlmfwdgzxulucv", model.backupSetName());
        Assertions.assertEquals(CreateMode.RECOVER, model.createMode());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-14T22:40:57Z"), model.deferredDeleteTimeInUtc());
        Assertions.assertEquals(false, model.isScheduledForDeferredDelete());
        Assertions.assertEquals("zvxurisjnhny", model.deferredDeleteTimeRemaining());
        Assertions.assertEquals(false, model.isDeferredDeleteScheduleUpcoming());
        Assertions.assertEquals(true, model.isRehydrate());
        Assertions.assertEquals("gxmrhublwp", model.resourceGuardOperationRequests().get(0));
        Assertions.assertEquals(true, model.isArchiveEnabled());
        Assertions.assertEquals("hej", model.policyName());
        Assertions.assertEquals(248529956, model.softDeleteRetentionPeriod());
        Assertions.assertEquals("xtqmieoxor", model.friendlyName());
        Assertions.assertEquals("ufhyaomtbgh", model.protectionStatus());
        Assertions.assertEquals(ProtectionState.PROTECTION_PAUSED, model.protectionState());
        Assertions.assertEquals("rvk", model.lastBackupStatus());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-21T11:52:27Z"), model.lastBackupTime());
        Assertions
            .assertEquals(
                ResourceHealthStatus.TRANSIENT_UNHEALTHY,
                model.kpisHealths().get("bibgjmfxumv").resourceHealthStatus());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-07-28T02:37:45Z"), model.extendedInfo().oldestRecoveryPoint());
        Assertions.assertEquals(277819924, model.extendedInfo().recoveryPointCount());
        Assertions.assertEquals("wdsh", model.extendedInfo().policyState());
    }

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