// 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.ProtectedItemResourceInner;
import com.azure.resourcemanager.recoveryservicesbackup.models.CreateMode;
import com.azure.resourcemanager.recoveryservicesbackup.models.ProtectedItem;
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 ProtectedItemResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ProtectedItemResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"protectedItemType\":\"ProtectedItem\",\"backupManagementType\":\"Invalid\",\"workloadType\":\"SAPHanaDBInstance\",\"containerName\":\"gujjugwdkcglh\",\"sourceResourceId\":\"azjdyggd\",\"policyId\":\"ixhbkuofqweykhm\",\"lastRecoveryPoint\":\"2021-08-01T10:52:51Z\",\"backupSetName\":\"fyexfwhy\",\"createMode\":\"Recover\",\"deferredDeleteTimeInUTC\":\"2021-02-12T00:37:49Z\",\"isScheduledForDeferredDelete\":true,\"deferredDeleteTimeRemaining\":\"c\",\"isDeferredDeleteScheduleUpcoming\":true,\"isRehydrate\":true,\"resourceGuardOperationRequests\":[\"amdecte\",\"f\"],\"isArchiveEnabled\":false,\"policyName\":\"jeyp\",\"softDeleteRetentionPeriod\":1237692135},\"eTag\":\"rkgqhcjrefo\",\"location\":\"gm\",\"tags\":{\"qjpkcattpngjcrc\":\"leyyvx\"},\"id\":\"zsqpjhvmdajvny\",\"name\":\"ounqecano\",\"type\":\"eupfhyhltrpm\"}")
                .toObject(ProtectedItemResourceInner.class);
        Assertions.assertEquals("gm", model.location());
        Assertions.assertEquals("leyyvx", model.tags().get("qjpkcattpngjcrc"));
        Assertions.assertEquals("gujjugwdkcglh", model.properties().containerName());
        Assertions.assertEquals("azjdyggd", model.properties().sourceResourceId());
        Assertions.assertEquals("ixhbkuofqweykhm", model.properties().policyId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-01T10:52:51Z"), model.properties().lastRecoveryPoint());
        Assertions.assertEquals("fyexfwhy", model.properties().backupSetName());
        Assertions.assertEquals(CreateMode.RECOVER, model.properties().createMode());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-02-12T00:37:49Z"), model.properties().deferredDeleteTimeInUtc());
        Assertions.assertEquals(true, model.properties().isScheduledForDeferredDelete());
        Assertions.assertEquals("c", model.properties().deferredDeleteTimeRemaining());
        Assertions.assertEquals(true, model.properties().isDeferredDeleteScheduleUpcoming());
        Assertions.assertEquals(true, model.properties().isRehydrate());
        Assertions.assertEquals("amdecte", model.properties().resourceGuardOperationRequests().get(0));
        Assertions.assertEquals(false, model.properties().isArchiveEnabled());
        Assertions.assertEquals("jeyp", model.properties().policyName());
        Assertions.assertEquals(1237692135, model.properties().softDeleteRetentionPeriod());
        Assertions.assertEquals("rkgqhcjrefo", model.etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ProtectedItemResourceInner model =
            new ProtectedItemResourceInner()
                .withLocation("gm")
                .withTags(mapOf("qjpkcattpngjcrc", "leyyvx"))
                .withProperties(
                    new ProtectedItem()
                        .withContainerName("gujjugwdkcglh")
                        .withSourceResourceId("azjdyggd")
                        .withPolicyId("ixhbkuofqweykhm")
                        .withLastRecoveryPoint(OffsetDateTime.parse("2021-08-01T10:52:51Z"))
                        .withBackupSetName("fyexfwhy")
                        .withCreateMode(CreateMode.RECOVER)
                        .withDeferredDeleteTimeInUtc(OffsetDateTime.parse("2021-02-12T00:37:49Z"))
                        .withIsScheduledForDeferredDelete(true)
                        .withDeferredDeleteTimeRemaining("c")
                        .withIsDeferredDeleteScheduleUpcoming(true)
                        .withIsRehydrate(true)
                        .withResourceGuardOperationRequests(Arrays.asList("amdecte", "f"))
                        .withIsArchiveEnabled(false)
                        .withPolicyName("jeyp")
                        .withSoftDeleteRetentionPeriod(1237692135))
                .withEtag("rkgqhcjrefo");
        model = BinaryData.fromObject(model).toObject(ProtectedItemResourceInner.class);
        Assertions.assertEquals("gm", model.location());
        Assertions.assertEquals("leyyvx", model.tags().get("qjpkcattpngjcrc"));
        Assertions.assertEquals("gujjugwdkcglh", model.properties().containerName());
        Assertions.assertEquals("azjdyggd", model.properties().sourceResourceId());
        Assertions.assertEquals("ixhbkuofqweykhm", model.properties().policyId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-01T10:52:51Z"), model.properties().lastRecoveryPoint());
        Assertions.assertEquals("fyexfwhy", model.properties().backupSetName());
        Assertions.assertEquals(CreateMode.RECOVER, model.properties().createMode());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-02-12T00:37:49Z"), model.properties().deferredDeleteTimeInUtc());
        Assertions.assertEquals(true, model.properties().isScheduledForDeferredDelete());
        Assertions.assertEquals("c", model.properties().deferredDeleteTimeRemaining());
        Assertions.assertEquals(true, model.properties().isDeferredDeleteScheduleUpcoming());
        Assertions.assertEquals(true, model.properties().isRehydrate());
        Assertions.assertEquals("amdecte", model.properties().resourceGuardOperationRequests().get(0));
        Assertions.assertEquals(false, model.properties().isArchiveEnabled());
        Assertions.assertEquals("jeyp", model.properties().policyName());
        Assertions.assertEquals(1237692135, model.properties().softDeleteRetentionPeriod());
        Assertions.assertEquals("rkgqhcjrefo", 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;
    }
}
