// 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.BackupResourceConfigResourceInner;
import com.azure.resourcemanager.recoveryservicesbackup.models.BackupResourceConfig;
import com.azure.resourcemanager.recoveryservicesbackup.models.DedupState;
import com.azure.resourcemanager.recoveryservicesbackup.models.StorageType;
import com.azure.resourcemanager.recoveryservicesbackup.models.StorageTypeState;
import com.azure.resourcemanager.recoveryservicesbackup.models.XcoolState;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class BackupResourceConfigResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        BackupResourceConfigResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"storageModelType\":\"Invalid\",\"storageType\":\"ZoneRedundant\",\"storageTypeState\":\"Invalid\",\"crossRegionRestoreFlag\":false,\"dedupState\":\"Invalid\",\"xcoolState\":\"Disabled\"},\"eTag\":\"m\",\"location\":\"hmtzopbsphrup\",\"tags\":{\"ycm\":\"sybbejhph\",\"htbmuf\":\"xaobhdxbmtqioqjz\",\"rxybqsoq\":\"ownoizhw\"},\"id\":\"jgkdmbpazlobcu\",\"name\":\"pdznrbtcqqjnqgl\",\"type\":\"qgn\"}")
                .toObject(BackupResourceConfigResourceInner.class);
        Assertions.assertEquals("hmtzopbsphrup", model.location());
        Assertions.assertEquals("sybbejhph", model.tags().get("ycm"));
        Assertions.assertEquals(StorageType.INVALID, model.properties().storageModelType());
        Assertions.assertEquals(StorageType.ZONE_REDUNDANT, model.properties().storageType());
        Assertions.assertEquals(StorageTypeState.INVALID, model.properties().storageTypeState());
        Assertions.assertEquals(false, model.properties().crossRegionRestoreFlag());
        Assertions.assertEquals(DedupState.INVALID, model.properties().dedupState());
        Assertions.assertEquals(XcoolState.DISABLED, model.properties().xcoolState());
        Assertions.assertEquals("m", model.etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        BackupResourceConfigResourceInner model =
            new BackupResourceConfigResourceInner()
                .withLocation("hmtzopbsphrup")
                .withTags(mapOf("ycm", "sybbejhph", "htbmuf", "xaobhdxbmtqioqjz", "rxybqsoq", "ownoizhw"))
                .withProperties(
                    new BackupResourceConfig()
                        .withStorageModelType(StorageType.INVALID)
                        .withStorageType(StorageType.ZONE_REDUNDANT)
                        .withStorageTypeState(StorageTypeState.INVALID)
                        .withCrossRegionRestoreFlag(false)
                        .withDedupState(DedupState.INVALID)
                        .withXcoolState(XcoolState.DISABLED))
                .withEtag("m");
        model = BinaryData.fromObject(model).toObject(BackupResourceConfigResourceInner.class);
        Assertions.assertEquals("hmtzopbsphrup", model.location());
        Assertions.assertEquals("sybbejhph", model.tags().get("ycm"));
        Assertions.assertEquals(StorageType.INVALID, model.properties().storageModelType());
        Assertions.assertEquals(StorageType.ZONE_REDUNDANT, model.properties().storageType());
        Assertions.assertEquals(StorageTypeState.INVALID, model.properties().storageTypeState());
        Assertions.assertEquals(false, model.properties().crossRegionRestoreFlag());
        Assertions.assertEquals(DedupState.INVALID, model.properties().dedupState());
        Assertions.assertEquals(XcoolState.DISABLED, model.properties().xcoolState());
        Assertions.assertEquals("m", 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;
    }
}
