// 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.resourcemanager.confidentialledger.models.AadBasedSecurityPrincipal;
import com.azure.resourcemanager.confidentialledger.models.CertBasedSecurityPrincipal;
import com.azure.resourcemanager.confidentialledger.models.ConfidentialLedger;
import com.azure.resourcemanager.confidentialledger.models.LedgerProperties;
import com.azure.resourcemanager.confidentialledger.models.LedgerRoleName;
import com.azure.resourcemanager.confidentialledger.models.LedgerType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/** Samples for Ledger Update. */
public final class LedgerUpdateSamples {
    /*
     * x-ms-original-file: specification/confidentialledger/resource-manager/Microsoft.ConfidentialLedger/preview/2023-01-26-preview/examples/ConfidentialLedger_Update.json
     */
    /**
     * Sample code: ConfidentialLedgerUpdate.
     *
     * @param manager Entry point to ConfidentialLedgerManager.
     */
    public static void confidentialLedgerUpdate(
        com.azure.resourcemanager.confidentialledger.ConfidentialLedgerManager manager) {
        ConfidentialLedger resource =
            manager
                .ledgers()
                .getByResourceGroupWithResponse(
                    "DummyResourceGroupName", "DummyLedgerName", com.azure.core.util.Context.NONE)
                .getValue();
        resource
            .update()
            .withTags(mapOf("additionProps2", "additional property value", "additionalProps1", "additional properties"))
            .withProperties(
                new LedgerProperties()
                    .withLedgerType(LedgerType.PUBLIC)
                    .withAadBasedSecurityPrincipals(
                        Arrays
                            .asList(
                                new AadBasedSecurityPrincipal()
                                    .withPrincipalId("34621747-6fc8-4771-a2eb-72f31c461f2e")
                                    .withTenantId("bce123b9-2b7b-4975-8360-5ca0b9b1cd08")
                                    .withLedgerRoleName(LedgerRoleName.ADMINISTRATOR)))
                    .withCertBasedSecurityPrincipals(
                        Arrays
                            .asList(
                                new CertBasedSecurityPrincipal()
                                    .withCert(
                                        "-----BEGIN CERTIFICATE-----\n"
                                            + "MIIDUjCCAjqgAwIBAgIQJ2IrDBawSkiAbkBY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aNjLelvWpeVb0m2aOSVXynrLwNCAVA=\n"
                                            + "-----END CERTIFICATE-----")
                                    .withLedgerRoleName(LedgerRoleName.READER))))
            .apply();
    }

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