// 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.GenericProtectedItem;
import com.azure.resourcemanager.recoveryservicesbackup.models.ProtectionState;
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 GenericProtectedItemTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        GenericProtectedItem model =
            BinaryData
                .fromString(
                    "{\"protectedItemType\":\"GenericProtectedItem\",\"friendlyName\":\"oxuztrksx\",\"policyState\":\"ndfcpfn\",\"protectionState\":\"BackupsSuspended\",\"protectedItemId\":8403793467545255222,\"sourceAssociations\":{\"amktcqiosmgbzah\":\"jaosrxuzv\",\"tz\":\"xqdlyrtltlapr\",\"s\":\"atbhjmznn\"},\"fabricName\":\"eq\",\"backupManagementType\":\"MAB\",\"workloadType\":\"Exchange\",\"containerName\":\"agunbtgfebw\",\"sourceResourceId\":\"bmhyreeudz\",\"policyId\":\"vbpdqmjxlyyzglgo\",\"lastRecoveryPoint\":\"2021-04-10T20:18:26Z\",\"backupSetName\":\"mjjyuojq\",\"createMode\":\"Invalid\",\"deferredDeleteTimeInUTC\":\"2021-10-09T07:53:12Z\",\"isScheduledForDeferredDelete\":false,\"deferredDeleteTimeRemaining\":\"ytunlbfjkwr\",\"isDeferredDeleteScheduleUpcoming\":true,\"isRehydrate\":false,\"resourceGuardOperationRequests\":[\"syrq\",\"njqhdenxa\"],\"isArchiveEnabled\":false,\"policyName\":\"akdkifmjnnawtqab\",\"softDeleteRetentionPeriod\":1329519591}")
                .toObject(GenericProtectedItem.class);
        Assertions.assertEquals("agunbtgfebw", model.containerName());
        Assertions.assertEquals("bmhyreeudz", model.sourceResourceId());
        Assertions.assertEquals("vbpdqmjxlyyzglgo", model.policyId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-04-10T20:18:26Z"), model.lastRecoveryPoint());
        Assertions.assertEquals("mjjyuojq", model.backupSetName());
        Assertions.assertEquals(CreateMode.INVALID, model.createMode());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-09T07:53:12Z"), model.deferredDeleteTimeInUtc());
        Assertions.assertEquals(false, model.isScheduledForDeferredDelete());
        Assertions.assertEquals("ytunlbfjkwr", model.deferredDeleteTimeRemaining());
        Assertions.assertEquals(true, model.isDeferredDeleteScheduleUpcoming());
        Assertions.assertEquals(false, model.isRehydrate());
        Assertions.assertEquals("syrq", model.resourceGuardOperationRequests().get(0));
        Assertions.assertEquals(false, model.isArchiveEnabled());
        Assertions.assertEquals("akdkifmjnnawtqab", model.policyName());
        Assertions.assertEquals(1329519591, model.softDeleteRetentionPeriod());
        Assertions.assertEquals("oxuztrksx", model.friendlyName());
        Assertions.assertEquals("ndfcpfn", model.policyState());
        Assertions.assertEquals(ProtectionState.BACKUPS_SUSPENDED, model.protectionState());
        Assertions.assertEquals(8403793467545255222L, model.protectedItemId());
        Assertions.assertEquals("jaosrxuzv", model.sourceAssociations().get("amktcqiosmgbzah"));
        Assertions.assertEquals("eq", model.fabricName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        GenericProtectedItem model =
            new GenericProtectedItem()
                .withContainerName("agunbtgfebw")
                .withSourceResourceId("bmhyreeudz")
                .withPolicyId("vbpdqmjxlyyzglgo")
                .withLastRecoveryPoint(OffsetDateTime.parse("2021-04-10T20:18:26Z"))
                .withBackupSetName("mjjyuojq")
                .withCreateMode(CreateMode.INVALID)
                .withDeferredDeleteTimeInUtc(OffsetDateTime.parse("2021-10-09T07:53:12Z"))
                .withIsScheduledForDeferredDelete(false)
                .withDeferredDeleteTimeRemaining("ytunlbfjkwr")
                .withIsDeferredDeleteScheduleUpcoming(true)
                .withIsRehydrate(false)
                .withResourceGuardOperationRequests(Arrays.asList("syrq", "njqhdenxa"))
                .withIsArchiveEnabled(false)
                .withPolicyName("akdkifmjnnawtqab")
                .withSoftDeleteRetentionPeriod(1329519591)
                .withFriendlyName("oxuztrksx")
                .withPolicyState("ndfcpfn")
                .withProtectionState(ProtectionState.BACKUPS_SUSPENDED)
                .withProtectedItemId(8403793467545255222L)
                .withSourceAssociations(mapOf("amktcqiosmgbzah", "jaosrxuzv", "tz", "xqdlyrtltlapr", "s", "atbhjmznn"))
                .withFabricName("eq");
        model = BinaryData.fromObject(model).toObject(GenericProtectedItem.class);
        Assertions.assertEquals("agunbtgfebw", model.containerName());
        Assertions.assertEquals("bmhyreeudz", model.sourceResourceId());
        Assertions.assertEquals("vbpdqmjxlyyzglgo", model.policyId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-04-10T20:18:26Z"), model.lastRecoveryPoint());
        Assertions.assertEquals("mjjyuojq", model.backupSetName());
        Assertions.assertEquals(CreateMode.INVALID, model.createMode());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-09T07:53:12Z"), model.deferredDeleteTimeInUtc());
        Assertions.assertEquals(false, model.isScheduledForDeferredDelete());
        Assertions.assertEquals("ytunlbfjkwr", model.deferredDeleteTimeRemaining());
        Assertions.assertEquals(true, model.isDeferredDeleteScheduleUpcoming());
        Assertions.assertEquals(false, model.isRehydrate());
        Assertions.assertEquals("syrq", model.resourceGuardOperationRequests().get(0));
        Assertions.assertEquals(false, model.isArchiveEnabled());
        Assertions.assertEquals("akdkifmjnnawtqab", model.policyName());
        Assertions.assertEquals(1329519591, model.softDeleteRetentionPeriod());
        Assertions.assertEquals("oxuztrksx", model.friendlyName());
        Assertions.assertEquals("ndfcpfn", model.policyState());
        Assertions.assertEquals(ProtectionState.BACKUPS_SUSPENDED, model.protectionState());
        Assertions.assertEquals(8403793467545255222L, model.protectedItemId());
        Assertions.assertEquals("jaosrxuzv", model.sourceAssociations().get("amktcqiosmgbzah"));
        Assertions.assertEquals("eq", model.fabricName());
    }

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