// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.dataprotection.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.dataprotection.models.ExistingResourcePolicy;
import com.azure.resourcemanager.dataprotection.models.KubernetesClusterRestoreCriteria;
import com.azure.resourcemanager.dataprotection.models.PersistentVolumeRestoreMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class KubernetesClusterRestoreCriteriaTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        KubernetesClusterRestoreCriteria model =
            BinaryData
                .fromString(
                    "{\"objectType\":\"KubernetesClusterRestoreCriteria\",\"includeClusterScopeResources\":true,\"includedNamespaces\":[\"wzrmuh\",\"pfcqdp\"],\"excludedNamespaces\":[\"qvpsvuoymg\"],\"includedResourceTypes\":[\"lvez\",\"ypql\",\"feo\"],\"excludedResourceTypes\":[\"qwkyhkobop\",\"xedk\"],\"labelSelectors\":[\"pbqpcrfkbwccsn\",\"vcdwxlpqekftn\",\"htjsying\"],\"persistentVolumeRestoreMode\":\"RestoreWithoutVolumeData\",\"conflictPolicy\":\"Patch\",\"namespaceMappings\":{\"szywkbirryu\":\"dhtmdvypgikd\",\"nrvgoupmfiibfgg\":\"hlhkjoqrvqqaatj\",\"wjygvjayvblmhvk\":\"ioolvrwxkvtkkgll\"}}")
                .toObject(KubernetesClusterRestoreCriteria.class);
        Assertions.assertEquals(true, model.includeClusterScopeResources());
        Assertions.assertEquals("wzrmuh", model.includedNamespaces().get(0));
        Assertions.assertEquals("qvpsvuoymg", model.excludedNamespaces().get(0));
        Assertions.assertEquals("lvez", model.includedResourceTypes().get(0));
        Assertions.assertEquals("qwkyhkobop", model.excludedResourceTypes().get(0));
        Assertions.assertEquals("pbqpcrfkbwccsn", model.labelSelectors().get(0));
        Assertions
            .assertEquals(PersistentVolumeRestoreMode.RESTORE_WITHOUT_VOLUME_DATA, model.persistentVolumeRestoreMode());
        Assertions.assertEquals(ExistingResourcePolicy.PATCH, model.conflictPolicy());
        Assertions.assertEquals("dhtmdvypgikd", model.namespaceMappings().get("szywkbirryu"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        KubernetesClusterRestoreCriteria model =
            new KubernetesClusterRestoreCriteria()
                .withIncludeClusterScopeResources(true)
                .withIncludedNamespaces(Arrays.asList("wzrmuh", "pfcqdp"))
                .withExcludedNamespaces(Arrays.asList("qvpsvuoymg"))
                .withIncludedResourceTypes(Arrays.asList("lvez", "ypql", "feo"))
                .withExcludedResourceTypes(Arrays.asList("qwkyhkobop", "xedk"))
                .withLabelSelectors(Arrays.asList("pbqpcrfkbwccsn", "vcdwxlpqekftn", "htjsying"))
                .withPersistentVolumeRestoreMode(PersistentVolumeRestoreMode.RESTORE_WITHOUT_VOLUME_DATA)
                .withConflictPolicy(ExistingResourcePolicy.PATCH)
                .withNamespaceMappings(
                    mapOf(
                        "szywkbirryu",
                        "dhtmdvypgikd",
                        "nrvgoupmfiibfgg",
                        "hlhkjoqrvqqaatj",
                        "wjygvjayvblmhvk",
                        "ioolvrwxkvtkkgll"));
        model = BinaryData.fromObject(model).toObject(KubernetesClusterRestoreCriteria.class);
        Assertions.assertEquals(true, model.includeClusterScopeResources());
        Assertions.assertEquals("wzrmuh", model.includedNamespaces().get(0));
        Assertions.assertEquals("qvpsvuoymg", model.excludedNamespaces().get(0));
        Assertions.assertEquals("lvez", model.includedResourceTypes().get(0));
        Assertions.assertEquals("qwkyhkobop", model.excludedResourceTypes().get(0));
        Assertions.assertEquals("pbqpcrfkbwccsn", model.labelSelectors().get(0));
        Assertions
            .assertEquals(PersistentVolumeRestoreMode.RESTORE_WITHOUT_VOLUME_DATA, model.persistentVolumeRestoreMode());
        Assertions.assertEquals(ExistingResourcePolicy.PATCH, model.conflictPolicy());
        Assertions.assertEquals("dhtmdvypgikd", model.namespaceMappings().get("szywkbirryu"));
    }

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