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

package com.azure.resourcemanager.apimanagement.generated;

import com.azure.core.management.serializer.SerializerFactory;
import com.azure.core.util.serializer.SerializerEncoding;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/** Samples for ContentItem CreateOrUpdate. */
public final class ContentItemCreateOrUpdateSamples {
    /*
     * x-ms-original-file: specification/apimanagement/resource-manager/Microsoft.ApiManagement/stable/2022-08-01/examples/ApiManagementCreateContentTypeContentItem.json
     */
    /**
     * Sample code: ApiManagementCreateContentTypeContentItem.
     *
     * @param manager Entry point to ApiManagementManager.
     */
    public static void apiManagementCreateContentTypeContentItem(
        com.azure.resourcemanager.apimanagement.ApiManagementManager manager) throws IOException {
        manager
            .contentItems()
            .define("4e3cf6a5-574a-ba08-1f23-2e7a38faa6d8")
            .withExistingContentType("rg1", "apimService1", "page")
            .withProperties(
                mapOf(
                    "en_us",
                    SerializerFactory
                        .createDefaultManagementSerializerAdapter()
                        .deserialize(
                            "{\"description\":\"Short story about the"
                                + " company.\",\"documentId\":\"contentTypes/document/contentItems/4e3cf6a5-574a-ba08-1f23-2e7a38faa6d8\",\"keywords\":\"company,"
                                + " about\",\"permalink\":\"/about\",\"title\":\"About\"}",
                            Object.class,
                            SerializerEncoding.JSON)))
            .create();
    }

    // Use "Map.of" if available
    @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;
    }
}
