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

package com.azure.resourcemanager.netapp.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.netapp.fluent.models.BackupPolicyInner;
import com.azure.resourcemanager.netapp.models.BackupPoliciesList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class BackupPoliciesListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        BackupPoliciesList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"etag\":\"iyntorzihle\",\"properties\":{\"backupPolicyId\":\"jswsrmslyz\",\"provisioningState\":\"zbchckqqzqioxiy\",\"dailyBackupsToKeep\":1721034864,\"weeklyBackupsToKeep\":1896138936,\"monthlyBackupsToKeep\":1822288960,\"volumesAssigned\":2066516032,\"enabled\":false,\"volumeBackups\":[]},\"location\":\"rwyhqmibzyhwitsm\",\"tags\":{\"biknsorgjhxbld\":\"ynpcdpumnzgmwznm\",\"dmtnc\":\"lwwrl\",\"tllxdyhgsyocogj\":\"ok\",\"kvci\":\"tdtbnnhadooc\"},\"id\":\"hnvpamqgxq\",\"name\":\"u\",\"type\":\"zikywgg\"},{\"etag\":\"allatmelwuipic\",\"properties\":{\"backupPolicyId\":\"zkzivgvvcnay\",\"provisioningState\":\"yrnxxmueedn\",\"dailyBackupsToKeep\":1429248323,\"weeklyBackupsToKeep\":233559890,\"monthlyBackupsToKeep\":928139019,\"volumesAssigned\":1199547484,\"enabled\":false,\"volumeBackups\":[]},\"location\":\"ealmfmtdaaygdvwv\",\"tags\":{\"qagvrvm\":\"ohgwxrtfudxepxg\",\"dblx\":\"pkukghi\",\"fnjhfjxwmszkkfo\":\"wi\"},\"id\":\"rey\",\"name\":\"kzikfjawneaivxwc\",\"type\":\"elpcirelsfeaenwa\"},{\"etag\":\"atklddxbjhwuaa\",\"properties\":{\"backupPolicyId\":\"zjosp\",\"provisioningState\":\"oulpjrv\",\"dailyBackupsToKeep\":1536946764,\"weeklyBackupsToKeep\":1986199851,\"monthlyBackupsToKeep\":1902797615,\"volumesAssigned\":1837530813,\"enabled\":true,\"volumeBackups\":[]},\"location\":\"tx\",\"tags\":{\"tq\":\"skfc\",\"gqggebdunygae\":\"miekkezzikhlyfjh\",\"fatpxllrxcyjmoa\":\"idb\",\"arm\":\"su\"},\"id\":\"wdmjsjqbjhhyx\",\"name\":\"rw\",\"type\":\"yc\"}]}")
                .toObject(BackupPoliciesList.class);
        Assertions.assertEquals("rwyhqmibzyhwitsm", model.value().get(0).location());
        Assertions.assertEquals("ynpcdpumnzgmwznm", model.value().get(0).tags().get("biknsorgjhxbld"));
        Assertions.assertEquals(1721034864, model.value().get(0).dailyBackupsToKeep());
        Assertions.assertEquals(1896138936, model.value().get(0).weeklyBackupsToKeep());
        Assertions.assertEquals(1822288960, model.value().get(0).monthlyBackupsToKeep());
        Assertions.assertEquals(false, model.value().get(0).enabled());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        BackupPoliciesList model =
            new BackupPoliciesList()
                .withValue(
                    Arrays
                        .asList(
                            new BackupPolicyInner()
                                .withLocation("rwyhqmibzyhwitsm")
                                .withTags(
                                    mapOf(
                                        "biknsorgjhxbld",
                                        "ynpcdpumnzgmwznm",
                                        "dmtnc",
                                        "lwwrl",
                                        "tllxdyhgsyocogj",
                                        "ok",
                                        "kvci",
                                        "tdtbnnhadooc"))
                                .withDailyBackupsToKeep(1721034864)
                                .withWeeklyBackupsToKeep(1896138936)
                                .withMonthlyBackupsToKeep(1822288960)
                                .withEnabled(false),
                            new BackupPolicyInner()
                                .withLocation("ealmfmtdaaygdvwv")
                                .withTags(
                                    mapOf("qagvrvm", "ohgwxrtfudxepxg", "dblx", "pkukghi", "fnjhfjxwmszkkfo", "wi"))
                                .withDailyBackupsToKeep(1429248323)
                                .withWeeklyBackupsToKeep(233559890)
                                .withMonthlyBackupsToKeep(928139019)
                                .withEnabled(false),
                            new BackupPolicyInner()
                                .withLocation("tx")
                                .withTags(
                                    mapOf(
                                        "tq",
                                        "skfc",
                                        "gqggebdunygae",
                                        "miekkezzikhlyfjh",
                                        "fatpxllrxcyjmoa",
                                        "idb",
                                        "arm",
                                        "su"))
                                .withDailyBackupsToKeep(1536946764)
                                .withWeeklyBackupsToKeep(1986199851)
                                .withMonthlyBackupsToKeep(1902797615)
                                .withEnabled(true)));
        model = BinaryData.fromObject(model).toObject(BackupPoliciesList.class);
        Assertions.assertEquals("rwyhqmibzyhwitsm", model.value().get(0).location());
        Assertions.assertEquals("ynpcdpumnzgmwznm", model.value().get(0).tags().get("biknsorgjhxbld"));
        Assertions.assertEquals(1721034864, model.value().get(0).dailyBackupsToKeep());
        Assertions.assertEquals(1896138936, model.value().get(0).weeklyBackupsToKeep());
        Assertions.assertEquals(1822288960, model.value().get(0).monthlyBackupsToKeep());
        Assertions.assertEquals(false, model.value().get(0).enabled());
    }

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