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

package com.azure.resourcemanager.eventgrid.generated;

import com.azure.core.management.serializer.SerializerFactory;
import com.azure.core.util.serializer.SerializerEncoding;
import com.azure.resourcemanager.eventgrid.models.ClientAuthentication;
import com.azure.resourcemanager.eventgrid.models.ClientCertificateSubjectDistinguishedName;
import com.azure.resourcemanager.eventgrid.models.ClientState;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/** Samples for Clients CreateOrUpdate. */
public final class ClientsCreateOrUpdateSamples {
    /*
     * x-ms-original-file: specification/eventgrid/resource-manager/Microsoft.EventGrid/preview/2023-06-01-preview/examples/Clients_CreateOrUpdate.json
     */
    /**
     * Sample code: Clients_CreateOrUpdate.
     *
     * @param manager Entry point to EventGridManager.
     */
    public static void clientsCreateOrUpdate(com.azure.resourcemanager.eventgrid.EventGridManager manager)
        throws IOException {
        manager
            .clients()
            .define("exampleClientName1")
            .withExistingNamespace("examplerg", "exampleNamespaceName1")
            .withDescription("This is a test client")
            .withAuthentication(
                new ClientAuthentication()
                    .withCertificateSubject(
                        new ClientCertificateSubjectDistinguishedName()
                            .withCommonName("CertificateCommonName")
                            .withOrganization("Microsoft")
                            .withOrganizationUnit("Azure")
                            .withCountryCode("fakeTokenPlaceholder")))
            .withState(ClientState.ENABLED)
            .withAttributes(
                mapOf(
                    "deviceTypes",
                    SerializerFactory
                        .createDefaultManagementSerializerAdapter()
                        .deserialize("[\"Fan\",\"Light\",\"AC\"]", Object.class, SerializerEncoding.JSON),
                    "floor",
                    3,
                    "room",
                    "345"))
            .create();
    }

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