// 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 com.azure.resourcemanager.apimanagement.models.SchemaType;
import java.io.IOException;

/** Samples for GlobalSchema CreateOrUpdate. */
public final class GlobalSchemaCreateOrUpdateSamples {
    /*
     * x-ms-original-file: specification/apimanagement/resource-manager/Microsoft.ApiManagement/stable/2021-08-01/examples/ApiManagementCreateGlobalSchema1.json
     */
    /**
     * Sample code: ApiManagementCreateSchema1.
     *
     * @param manager Entry point to ApiManagementManager.
     */
    public static void apiManagementCreateSchema1(
        com.azure.resourcemanager.apimanagement.ApiManagementManager manager) {
        manager
            .globalSchemas()
            .define("schema1")
            .withExistingService("rg1", "apimService1")
            .withSchemaType(SchemaType.XML)
            .withDescription("sample schema description")
            .withValue(
                "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\r\n"
                    + "           xmlns:tns=\"http://tempuri.org/PurchaseOrderSchema.xsd\"\r\n"
                    + "           targetNamespace=\"http://tempuri.org/PurchaseOrderSchema.xsd\"\r\n"
                    + "           elementFormDefault=\"qualified\">\r\n"
                    + " <xsd:element name=\"PurchaseOrder\" type=\"tns:PurchaseOrderType\"/>\r\n"
                    + " <xsd:complexType name=\"PurchaseOrderType\">\r\n"
                    + "  <xsd:sequence>\r\n"
                    + "   <xsd:element name=\"ShipTo\" type=\"tns:USAddress\" maxOccurs=\"2\"/>\r\n"
                    + "   <xsd:element name=\"BillTo\" type=\"tns:USAddress\"/>\r\n"
                    + "  </xsd:sequence>\r\n"
                    + "  <xsd:attribute name=\"OrderDate\" type=\"xsd:date\"/>\r\n"
                    + " </xsd:complexType>\r\n\r\n"
                    + " <xsd:complexType name=\"USAddress\">\r\n"
                    + "  <xsd:sequence>\r\n"
                    + "   <xsd:element name=\"name\"   type=\"xsd:string\"/>\r\n"
                    + "   <xsd:element name=\"street\" type=\"xsd:string\"/>\r\n"
                    + "   <xsd:element name=\"city\"   type=\"xsd:string\"/>\r\n"
                    + "   <xsd:element name=\"state\"  type=\"xsd:string\"/>\r\n"
                    + "   <xsd:element name=\"zip\"    type=\"xsd:integer\"/>\r\n"
                    + "  </xsd:sequence>\r\n"
                    + "  <xsd:attribute name=\"country\" type=\"xsd:NMTOKEN\" fixed=\"US\"/>\r\n"
                    + " </xsd:complexType>\r\n"
                    + "</xsd:schema>")
            .create();
    }

    /*
     * x-ms-original-file: specification/apimanagement/resource-manager/Microsoft.ApiManagement/stable/2021-08-01/examples/ApiManagementCreateGlobalSchema2.json
     */
    /**
     * Sample code: ApiManagementCreateSchema2.
     *
     * @param manager Entry point to ApiManagementManager.
     */
    public static void apiManagementCreateSchema2(com.azure.resourcemanager.apimanagement.ApiManagementManager manager)
        throws IOException {
        manager
            .globalSchemas()
            .define("schema1")
            .withExistingService("rg1", "apimService1")
            .withSchemaType(SchemaType.JSON)
            .withDescription("sample schema description")
            .withDocument(
                SerializerFactory
                    .createDefaultManagementSerializerAdapter()
                    .deserialize(
                        "{\"type\":\"object\",\"$id\":\"https://example.com/person.schema.json\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"properties\":{\"age\":{\"type\":\"integer\",\"description\":\"Age"
                            + " in years which must be equal to or greater than"
                            + " zero.\",\"minimum\":0},\"firstName\":{\"type\":\"string\",\"description\":\"The"
                            + " person's first name.\"},\"lastName\":{\"type\":\"string\",\"description\":\"The"
                            + " person's last name.\"}},\"title\":\"Person\"}",
                        Object.class,
                        SerializerEncoding.JSON))
            .create();
    }
}
