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

package com.azure.resourcemanager.confidentialledger.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.confidentialledger.fluent.models.ConfidentialLedgerInner;
import com.azure.resourcemanager.confidentialledger.models.ConfidentialLedgerList;
import com.azure.resourcemanager.confidentialledger.models.LedgerProperties;
import com.azure.resourcemanager.confidentialledger.models.LedgerType;
import com.azure.resourcemanager.confidentialledger.models.RunningState;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ConfidentialLedgerListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ConfidentialLedgerList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"ledgerName\":\"wjzrnfygxgisp\",\"ledgerUri\":\"vtz\",\"identityServiceUri\":\"ufubl\",\"ledgerInternalNamespace\":\"fxqeof\",\"runningState\":\"Active\",\"ledgerType\":\"Private\",\"provisioningState\":\"Creating\",\"aadBasedSecurityPrincipals\":[],\"certBasedSecurityPrincipals\":[]},\"location\":\"s\",\"tags\":{\"nbybkzgcwrwcl\":\"mjqulngsn\",\"cjdkwtnhxbnjbi\":\"xwrljdouskcqvkoc\",\"jwnzlljfmp\":\"sqrglssainq\",\"yqduujit\":\"eebvmgxsab\"},\"id\":\"jczdzevndh\",\"name\":\"rwpdappdsbdkvwrw\",\"type\":\"feusnhut\"},{\"properties\":{\"ledgerName\":\"tmrldhugjzzdatq\",\"ledgerUri\":\"oc\",\"identityServiceUri\":\"eablg\",\"ledgerInternalNamespace\":\"uticndvkaozwyif\",\"runningState\":\"Resuming\",\"ledgerType\":\"Private\",\"provisioningState\":\"Unknown\",\"aadBasedSecurityPrincipals\":[],\"certBasedSecurityPrincipals\":[]},\"location\":\"tyxolniwpwc\",\"tags\":{\"ryplwckbasyypn\":\"fkgiawxk\",\"phejkotynqgoulz\":\"dhsgcba\",\"gakeqsr\":\"dlikwyqkgfgibma\"},\"id\":\"yb\",\"name\":\"qqedqytbciqfou\",\"type\":\"lmmnkzsmodmglo\"}],\"nextLink\":\"pbkwtmu\"}")
                .toObject(ConfidentialLedgerList.class);
        Assertions.assertEquals("s", model.value().get(0).location());
        Assertions.assertEquals("mjqulngsn", model.value().get(0).tags().get("nbybkzgcwrwcl"));
        Assertions.assertEquals(RunningState.ACTIVE, model.value().get(0).properties().runningState());
        Assertions.assertEquals(LedgerType.PRIVATE, model.value().get(0).properties().ledgerType());
        Assertions.assertEquals("pbkwtmu", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ConfidentialLedgerList model =
            new ConfidentialLedgerList()
                .withValue(
                    Arrays
                        .asList(
                            new ConfidentialLedgerInner()
                                .withLocation("s")
                                .withTags(
                                    mapOf(
                                        "nbybkzgcwrwcl",
                                        "mjqulngsn",
                                        "cjdkwtnhxbnjbi",
                                        "xwrljdouskcqvkoc",
                                        "jwnzlljfmp",
                                        "sqrglssainq",
                                        "yqduujit",
                                        "eebvmgxsab"))
                                .withProperties(
                                    new LedgerProperties()
                                        .withRunningState(RunningState.ACTIVE)
                                        .withLedgerType(LedgerType.PRIVATE)
                                        .withAadBasedSecurityPrincipals(Arrays.asList())
                                        .withCertBasedSecurityPrincipals(Arrays.asList())),
                            new ConfidentialLedgerInner()
                                .withLocation("tyxolniwpwc")
                                .withTags(
                                    mapOf(
                                        "ryplwckbasyypn",
                                        "fkgiawxk",
                                        "phejkotynqgoulz",
                                        "dhsgcba",
                                        "gakeqsr",
                                        "dlikwyqkgfgibma"))
                                .withProperties(
                                    new LedgerProperties()
                                        .withRunningState(RunningState.RESUMING)
                                        .withLedgerType(LedgerType.PRIVATE)
                                        .withAadBasedSecurityPrincipals(Arrays.asList())
                                        .withCertBasedSecurityPrincipals(Arrays.asList()))))
                .withNextLink("pbkwtmu");
        model = BinaryData.fromObject(model).toObject(ConfidentialLedgerList.class);
        Assertions.assertEquals("s", model.value().get(0).location());
        Assertions.assertEquals("mjqulngsn", model.value().get(0).tags().get("nbybkzgcwrwcl"));
        Assertions.assertEquals(RunningState.ACTIVE, model.value().get(0).properties().runningState());
        Assertions.assertEquals(LedgerType.PRIVATE, model.value().get(0).properties().ledgerType());
        Assertions.assertEquals("pbkwtmu", model.nextLink());
    }

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