// 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.AadBasedSecurityPrincipal;
import com.azure.resourcemanager.confidentialledger.models.CertBasedSecurityPrincipal;
import com.azure.resourcemanager.confidentialledger.models.LedgerProperties;
import com.azure.resourcemanager.confidentialledger.models.LedgerRoleName;
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 ConfidentialLedgerInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ConfidentialLedgerInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"ledgerName\":\"lzufcyzkohdbi\",\"ledgerUri\":\"nufhf\",\"identityServiceUri\":\"jysagith\",\"ledgerInternalNamespace\":\"hab\",\"runningState\":\"Pausing\",\"ledgerType\":\"Private\",\"provisioningState\":\"Updating\",\"aadBasedSecurityPrincipals\":[{\"principalId\":\"yscnpqxu\",\"tenantId\":\"vyq\",\"ledgerRoleName\":\"Reader\"}],\"certBasedSecurityPrincipals\":[{\"cert\":\"rkxvdum\",\"ledgerRoleName\":\"Contributor\"}]},\"location\":\"fwvuk\",\"tags\":{\"yejhk\":\"udccsnhsjc\",\"kkvnipjox\":\"yhtnapczwlokjye\",\"podmailzydehojwy\":\"jnchgej\"},\"id\":\"huxinpmqnj\",\"name\":\"qwixjspro\",\"type\":\"vcputegj\"}")
                .toObject(ConfidentialLedgerInner.class);
        Assertions.assertEquals("fwvuk", model.location());
        Assertions.assertEquals("udccsnhsjc", model.tags().get("yejhk"));
        Assertions.assertEquals(RunningState.PAUSING, model.properties().runningState());
        Assertions.assertEquals(LedgerType.PRIVATE, model.properties().ledgerType());
        Assertions.assertEquals("yscnpqxu", model.properties().aadBasedSecurityPrincipals().get(0).principalId());
        Assertions.assertEquals("vyq", model.properties().aadBasedSecurityPrincipals().get(0).tenantId());
        Assertions
            .assertEquals(
                LedgerRoleName.READER, model.properties().aadBasedSecurityPrincipals().get(0).ledgerRoleName());
        Assertions.assertEquals("rkxvdum", model.properties().certBasedSecurityPrincipals().get(0).cert());
        Assertions
            .assertEquals(
                LedgerRoleName.CONTRIBUTOR, model.properties().certBasedSecurityPrincipals().get(0).ledgerRoleName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ConfidentialLedgerInner model =
            new ConfidentialLedgerInner()
                .withLocation("fwvuk")
                .withTags(mapOf("yejhk", "udccsnhsjc", "kkvnipjox", "yhtnapczwlokjye", "podmailzydehojwy", "jnchgej"))
                .withProperties(
                    new LedgerProperties()
                        .withRunningState(RunningState.PAUSING)
                        .withLedgerType(LedgerType.PRIVATE)
                        .withAadBasedSecurityPrincipals(
                            Arrays
                                .asList(
                                    new AadBasedSecurityPrincipal()
                                        .withPrincipalId("yscnpqxu")
                                        .withTenantId("vyq")
                                        .withLedgerRoleName(LedgerRoleName.READER)))
                        .withCertBasedSecurityPrincipals(
                            Arrays
                                .asList(
                                    new CertBasedSecurityPrincipal()
                                        .withCert("rkxvdum")
                                        .withLedgerRoleName(LedgerRoleName.CONTRIBUTOR))));
        model = BinaryData.fromObject(model).toObject(ConfidentialLedgerInner.class);
        Assertions.assertEquals("fwvuk", model.location());
        Assertions.assertEquals("udccsnhsjc", model.tags().get("yejhk"));
        Assertions.assertEquals(RunningState.PAUSING, model.properties().runningState());
        Assertions.assertEquals(LedgerType.PRIVATE, model.properties().ledgerType());
        Assertions.assertEquals("yscnpqxu", model.properties().aadBasedSecurityPrincipals().get(0).principalId());
        Assertions.assertEquals("vyq", model.properties().aadBasedSecurityPrincipals().get(0).tenantId());
        Assertions
            .assertEquals(
                LedgerRoleName.READER, model.properties().aadBasedSecurityPrincipals().get(0).ledgerRoleName());
        Assertions.assertEquals("rkxvdum", model.properties().certBasedSecurityPrincipals().get(0).cert());
        Assertions
            .assertEquals(
                LedgerRoleName.CONTRIBUTOR, model.properties().certBasedSecurityPrincipals().get(0).ledgerRoleName());
    }

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