// 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.util.Context;
import com.azure.resourcemanager.apimanagement.fluent.models.PolicyContractInner;
import com.azure.resourcemanager.apimanagement.models.PolicyContentFormat;
import com.azure.resourcemanager.apimanagement.models.PolicyIdName;

/** Samples for ProductPolicy CreateOrUpdate. */
public final class ProductPolicyCreateOrUpdateSamples {
    /*
     * x-ms-original-file: specification/apimanagement/resource-manager/Microsoft.ApiManagement/stable/2021-08-01/examples/ApiManagementCreateProductPolicy.json
     */
    /**
     * Sample code: ApiManagementCreateProductPolicy.
     *
     * @param manager Entry point to ApiManagementManager.
     */
    public static void apiManagementCreateProductPolicy(
        com.azure.resourcemanager.apimanagement.ApiManagementManager manager) {
        manager
            .productPolicies()
            .createOrUpdateWithResponse(
                "rg1",
                "apimService1",
                "5702e97e5157a50f48dce801",
                PolicyIdName.POLICY,
                new PolicyContractInner()
                    .withValue(
                        "<policies>\r\n"
                            + "  <inbound>\r\n"
                            + "    <rate-limit calls=\"{{call-count}}\" renewal-period=\"15\"></rate-limit>\r\n"
                            + "    <log-to-eventhub logger-id=\"16\">\r\n"
                            + "                      @( string.Join(\",\", DateTime.UtcNow,"
                            + " context.Deployment.ServiceName, context.RequestId, context.Request.IpAddress,"
                            + " context.Operation.Name) ) \r\n"
                            + "                  </log-to-eventhub>\r\n"
                            + "    <quota-by-key calls=\"40\" counter-key=\"cc\" renewal-period=\"3600\""
                            + " increment-count=\"@(context.Request.Method == &quot;POST&quot; ? 1:2)\" />\r\n"
                            + "    <base />\r\n"
                            + "  </inbound>\r\n"
                            + "  <backend>\r\n"
                            + "    <base />\r\n"
                            + "  </backend>\r\n"
                            + "  <outbound>\r\n"
                            + "    <base />\r\n"
                            + "  </outbound>\r\n"
                            + "</policies>")
                    .withFormat(PolicyContentFormat.XML),
                null,
                Context.NONE);
    }
}
