// 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.CreateMode;
import com.azure.resourcemanager.recoveryservicesbackup.models.DpmProtectedItem;
import com.azure.resourcemanager.recoveryservicesbackup.models.DpmProtectedItemExtendedInfo;
import com.azure.resourcemanager.recoveryservicesbackup.models.ProtectedItemState;
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 DpmProtectedItemTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        DpmProtectedItem model =
            BinaryData
                .fromString(
                    "{\"protectedItemType\":\"DPMProtectedItem\",\"friendlyName\":\"egizv\",\"backupEngineName\":\"felisdjub\",\"protectionState\":\"IRPending\",\"extendedInfo\":{\"protectableObjectLoadPath\":{\"m\":\"kxkbsazgakgacyr\",\"pv\":\"dmspof\",\"iofrzgbzjedmstk\":\"hryl\"},\"protected\":false,\"isPresentOnCloud\":true,\"lastBackupStatus\":\"c\",\"lastRefreshedAt\":\"2021-11-07T19:34:50Z\",\"oldestRecoveryPoint\":\"2021-03-22T01:54:17Z\",\"recoveryPointCount\":1363158856,\"onPremiseOldestRecoveryPoint\":\"2021-03-28T09:03:38Z\",\"onPremiseLatestRecoveryPoint\":\"2021-04-27T21:47:04Z\",\"onPremiseRecoveryPointCount\":386349585,\"isCollocated\":true,\"protectionGroupName\":\"ibmikostbzb\",\"diskStorageUsedInBytes\":\"wbuqn\",\"totalDiskStorageSizeInBytes\":\"phzfylsgcrp\"},\"backupManagementType\":\"Invalid\",\"workloadType\":\"SAPHanaDBInstance\",\"containerName\":\"zzcezelfwyfwlw\",\"sourceResourceId\":\"wetnpsihc\",\"policyId\":\"fzvaylptr\",\"lastRecoveryPoint\":\"2021-08-23T02:35:52Z\",\"backupSetName\":\"ztcmwq\",\"createMode\":\"Default\",\"deferredDeleteTimeInUTC\":\"2021-11-26T04:41:12Z\",\"isScheduledForDeferredDelete\":false,\"deferredDeleteTimeRemaining\":\"fewz\",\"isDeferredDeleteScheduleUpcoming\":true,\"isRehydrate\":true,\"resourceGuardOperationRequests\":[\"eqvhpsylkk\",\"hkbffmbm\"],\"isArchiveEnabled\":true,\"policyName\":\"gywwpgjxs\",\"softDeleteRetentionPeriod\":420950795}")
                .toObject(DpmProtectedItem.class);
        Assertions.assertEquals("zzcezelfwyfwlw", model.containerName());
        Assertions.assertEquals("wetnpsihc", model.sourceResourceId());
        Assertions.assertEquals("fzvaylptr", model.policyId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-23T02:35:52Z"), model.lastRecoveryPoint());
        Assertions.assertEquals("ztcmwq", model.backupSetName());
        Assertions.assertEquals(CreateMode.DEFAULT, model.createMode());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-26T04:41:12Z"), model.deferredDeleteTimeInUtc());
        Assertions.assertEquals(false, model.isScheduledForDeferredDelete());
        Assertions.assertEquals("fewz", model.deferredDeleteTimeRemaining());
        Assertions.assertEquals(true, model.isDeferredDeleteScheduleUpcoming());
        Assertions.assertEquals(true, model.isRehydrate());
        Assertions.assertEquals("eqvhpsylkk", model.resourceGuardOperationRequests().get(0));
        Assertions.assertEquals(true, model.isArchiveEnabled());
        Assertions.assertEquals("gywwpgjxs", model.policyName());
        Assertions.assertEquals(420950795, model.softDeleteRetentionPeriod());
        Assertions.assertEquals("egizv", model.friendlyName());
        Assertions.assertEquals("felisdjub", model.backupEngineName());
        Assertions.assertEquals(ProtectedItemState.IRPENDING, model.protectionState());
        Assertions.assertEquals("kxkbsazgakgacyr", model.extendedInfo().protectableObjectLoadPath().get("m"));
        Assertions.assertEquals(false, model.extendedInfo().protectedProperty());
        Assertions.assertEquals(true, model.extendedInfo().isPresentOnCloud());
        Assertions.assertEquals("c", model.extendedInfo().lastBackupStatus());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-07T19:34:50Z"), model.extendedInfo().lastRefreshedAt());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-03-22T01:54:17Z"), model.extendedInfo().oldestRecoveryPoint());
        Assertions.assertEquals(1363158856, model.extendedInfo().recoveryPointCount());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-03-28T09:03:38Z"), model.extendedInfo().onPremiseOldestRecoveryPoint());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-04-27T21:47:04Z"), model.extendedInfo().onPremiseLatestRecoveryPoint());
        Assertions.assertEquals(386349585, model.extendedInfo().onPremiseRecoveryPointCount());
        Assertions.assertEquals(true, model.extendedInfo().isCollocated());
        Assertions.assertEquals("ibmikostbzb", model.extendedInfo().protectionGroupName());
        Assertions.assertEquals("wbuqn", model.extendedInfo().diskStorageUsedInBytes());
        Assertions.assertEquals("phzfylsgcrp", model.extendedInfo().totalDiskStorageSizeInBytes());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        DpmProtectedItem model =
            new DpmProtectedItem()
                .withContainerName("zzcezelfwyfwlw")
                .withSourceResourceId("wetnpsihc")
                .withPolicyId("fzvaylptr")
                .withLastRecoveryPoint(OffsetDateTime.parse("2021-08-23T02:35:52Z"))
                .withBackupSetName("ztcmwq")
                .withCreateMode(CreateMode.DEFAULT)
                .withDeferredDeleteTimeInUtc(OffsetDateTime.parse("2021-11-26T04:41:12Z"))
                .withIsScheduledForDeferredDelete(false)
                .withDeferredDeleteTimeRemaining("fewz")
                .withIsDeferredDeleteScheduleUpcoming(true)
                .withIsRehydrate(true)
                .withResourceGuardOperationRequests(Arrays.asList("eqvhpsylkk", "hkbffmbm"))
                .withIsArchiveEnabled(true)
                .withPolicyName("gywwpgjxs")
                .withSoftDeleteRetentionPeriod(420950795)
                .withFriendlyName("egizv")
                .withBackupEngineName("felisdjub")
                .withProtectionState(ProtectedItemState.IRPENDING)
                .withExtendedInfo(
                    new DpmProtectedItemExtendedInfo()
                        .withProtectableObjectLoadPath(
                            mapOf("m", "kxkbsazgakgacyr", "pv", "dmspof", "iofrzgbzjedmstk", "hryl"))
                        .withProtectedProperty(false)
                        .withIsPresentOnCloud(true)
                        .withLastBackupStatus("c")
                        .withLastRefreshedAt(OffsetDateTime.parse("2021-11-07T19:34:50Z"))
                        .withOldestRecoveryPoint(OffsetDateTime.parse("2021-03-22T01:54:17Z"))
                        .withRecoveryPointCount(1363158856)
                        .withOnPremiseOldestRecoveryPoint(OffsetDateTime.parse("2021-03-28T09:03:38Z"))
                        .withOnPremiseLatestRecoveryPoint(OffsetDateTime.parse("2021-04-27T21:47:04Z"))
                        .withOnPremiseRecoveryPointCount(386349585)
                        .withIsCollocated(true)
                        .withProtectionGroupName("ibmikostbzb")
                        .withDiskStorageUsedInBytes("wbuqn")
                        .withTotalDiskStorageSizeInBytes("phzfylsgcrp"));
        model = BinaryData.fromObject(model).toObject(DpmProtectedItem.class);
        Assertions.assertEquals("zzcezelfwyfwlw", model.containerName());
        Assertions.assertEquals("wetnpsihc", model.sourceResourceId());
        Assertions.assertEquals("fzvaylptr", model.policyId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-23T02:35:52Z"), model.lastRecoveryPoint());
        Assertions.assertEquals("ztcmwq", model.backupSetName());
        Assertions.assertEquals(CreateMode.DEFAULT, model.createMode());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-26T04:41:12Z"), model.deferredDeleteTimeInUtc());
        Assertions.assertEquals(false, model.isScheduledForDeferredDelete());
        Assertions.assertEquals("fewz", model.deferredDeleteTimeRemaining());
        Assertions.assertEquals(true, model.isDeferredDeleteScheduleUpcoming());
        Assertions.assertEquals(true, model.isRehydrate());
        Assertions.assertEquals("eqvhpsylkk", model.resourceGuardOperationRequests().get(0));
        Assertions.assertEquals(true, model.isArchiveEnabled());
        Assertions.assertEquals("gywwpgjxs", model.policyName());
        Assertions.assertEquals(420950795, model.softDeleteRetentionPeriod());
        Assertions.assertEquals("egizv", model.friendlyName());
        Assertions.assertEquals("felisdjub", model.backupEngineName());
        Assertions.assertEquals(ProtectedItemState.IRPENDING, model.protectionState());
        Assertions.assertEquals("kxkbsazgakgacyr", model.extendedInfo().protectableObjectLoadPath().get("m"));
        Assertions.assertEquals(false, model.extendedInfo().protectedProperty());
        Assertions.assertEquals(true, model.extendedInfo().isPresentOnCloud());
        Assertions.assertEquals("c", model.extendedInfo().lastBackupStatus());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-07T19:34:50Z"), model.extendedInfo().lastRefreshedAt());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-03-22T01:54:17Z"), model.extendedInfo().oldestRecoveryPoint());
        Assertions.assertEquals(1363158856, model.extendedInfo().recoveryPointCount());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-03-28T09:03:38Z"), model.extendedInfo().onPremiseOldestRecoveryPoint());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-04-27T21:47:04Z"), model.extendedInfo().onPremiseLatestRecoveryPoint());
        Assertions.assertEquals(386349585, model.extendedInfo().onPremiseRecoveryPointCount());
        Assertions.assertEquals(true, model.extendedInfo().isCollocated());
        Assertions.assertEquals("ibmikostbzb", model.extendedInfo().protectionGroupName());
        Assertions.assertEquals("wbuqn", model.extendedInfo().diskStorageUsedInBytes());
        Assertions.assertEquals("phzfylsgcrp", model.extendedInfo().totalDiskStorageSizeInBytes());
    }

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