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

package com.azure.resourcemanager.logic.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.logic.fluent.models.ApiOperationInner;
import com.azure.resourcemanager.logic.models.ApiOperationAnnotation;
import com.azure.resourcemanager.logic.models.ApiOperationPropertiesDefinition;
import com.azure.resourcemanager.logic.models.ApiReference;
import com.azure.resourcemanager.logic.models.ApiTier;
import com.azure.resourcemanager.logic.models.StatusAnnotation;
import com.azure.resourcemanager.logic.models.SwaggerSchema;
import com.azure.resourcemanager.logic.models.SwaggerSchemaType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ApiOperationInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ApiOperationInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"summary\":\"crwnamikz\",\"description\":\"rqbsmswziq\",\"visibility\":\"uhok\",\"trigger\":\"uswhvhczznvfbycj\",\"triggerHint\":\"jww\",\"pageable\":false,\"annotation\":{\"status\":\"Production\",\"family\":\"mxqhndvnoamldse\",\"revision\":757674973},\"api\":{\"displayName\":\"jhhflzokxcoxpel\",\"description\":\"eta\",\"iconUri\":\"tsxoatftgz\",\"swagger\":\"datapbswvefloccsrm\",\"brandColor\":\"ihmipgawtxxpk\",\"category\":\"Enterprise\",\"id\":\"jxgrytfmp\",\"name\":\"cil\",\"type\":\"caykggnoxuz\"},\"inputsDefinition\":{\"ref\":\"sxwpndfcpfnznthj\",\"type\":\"Array\",\"title\":\"aosrxuz\",\"properties\":{},\"additionalProperties\":\"datatcqiosmg\",\"required\":[\"hgxqdlyrt\"],\"maxProperties\":1395240119,\"minProperties\":1207398584,\"allOf\":[],\"discriminator\":\"zkatb\",\"readOnly\":true,\"example\":\"databsoqeqala\",\"notificationUrlExtension\":false},\"responsesDefinition\":{\"kpak\":{\"ref\":\"febwlnbmhyreeudz\",\"type\":\"Null\",\"title\":\"pdqmjxlyyzglgouw\",\"properties\":{},\"additionalProperties\":\"datajyuojqtobaxkjeyt\",\"required\":[],\"maxProperties\":1073974691,\"minProperties\":254445190,\"allOf\":[],\"discriminator\":\"rusnk\",\"readOnly\":false,\"example\":\"dataqunjqh\",\"notificationUrlExtension\":false},\"saasiixtmkzj\":{\"ref\":\"ifmjnn\",\"type\":\"File\",\"title\":\"abpxuc\",\"properties\":{},\"additionalProperties\":\"dataqoweyirdhl\",\"required\":[],\"maxProperties\":1189308614,\"minProperties\":351115849,\"allOf\":[],\"discriminator\":\"qmp\",\"readOnly\":true,\"example\":\"datapqxpx\",\"notificationUrlExtension\":false}},\"isWebhook\":true,\"isNotification\":true},\"location\":\"rhgfgrwsdpgrat\",\"tags\":{\"tbrxkjz\":\"bglbyvict\"},\"id\":\"rgxffmshkw\",\"name\":\"bkgozxwopdbydpi\",\"type\":\"qaclnapxbiy\"}")
                .toObject(ApiOperationInner.class);
        Assertions.assertEquals("rhgfgrwsdpgrat", model.location());
        Assertions.assertEquals("bglbyvict", model.tags().get("tbrxkjz"));
        Assertions.assertEquals("crwnamikz", model.properties().summary());
        Assertions.assertEquals("rqbsmswziq", model.properties().description());
        Assertions.assertEquals("uhok", model.properties().visibility());
        Assertions.assertEquals("uswhvhczznvfbycj", model.properties().trigger());
        Assertions.assertEquals("jww", model.properties().triggerHint());
        Assertions.assertEquals(false, model.properties().pageable());
        Assertions.assertEquals(StatusAnnotation.PRODUCTION, model.properties().annotation().status());
        Assertions.assertEquals("mxqhndvnoamldse", model.properties().annotation().family());
        Assertions.assertEquals(757674973, model.properties().annotation().revision());
        Assertions.assertEquals("jxgrytfmp", model.properties().api().id());
        Assertions.assertEquals("jhhflzokxcoxpel", model.properties().api().displayName());
        Assertions.assertEquals("eta", model.properties().api().description());
        Assertions.assertEquals("tsxoatftgz", model.properties().api().iconUri());
        Assertions.assertEquals("ihmipgawtxxpk", model.properties().api().brandColor());
        Assertions.assertEquals(ApiTier.ENTERPRISE, model.properties().api().category());
        Assertions.assertEquals("sxwpndfcpfnznthj", model.properties().inputsDefinition().ref());
        Assertions.assertEquals(SwaggerSchemaType.ARRAY, model.properties().inputsDefinition().type());
        Assertions.assertEquals("aosrxuz", model.properties().inputsDefinition().title());
        Assertions.assertEquals("hgxqdlyrt", model.properties().inputsDefinition().required().get(0));
        Assertions.assertEquals(1395240119, model.properties().inputsDefinition().maxProperties());
        Assertions.assertEquals(1207398584, model.properties().inputsDefinition().minProperties());
        Assertions.assertEquals("zkatb", model.properties().inputsDefinition().discriminator());
        Assertions.assertEquals(true, model.properties().inputsDefinition().readOnly());
        Assertions.assertEquals(false, model.properties().inputsDefinition().notificationUrlExtension());
        Assertions.assertEquals("febwlnbmhyreeudz", model.properties().responsesDefinition().get("kpak").ref());
        Assertions.assertEquals(SwaggerSchemaType.NULL, model.properties().responsesDefinition().get("kpak").type());
        Assertions.assertEquals("pdqmjxlyyzglgouw", model.properties().responsesDefinition().get("kpak").title());
        Assertions.assertEquals(1073974691, model.properties().responsesDefinition().get("kpak").maxProperties());
        Assertions.assertEquals(254445190, model.properties().responsesDefinition().get("kpak").minProperties());
        Assertions.assertEquals("rusnk", model.properties().responsesDefinition().get("kpak").discriminator());
        Assertions.assertEquals(false, model.properties().responsesDefinition().get("kpak").readOnly());
        Assertions.assertEquals(false, model.properties().responsesDefinition().get("kpak").notificationUrlExtension());
        Assertions.assertEquals(true, model.properties().isWebhook());
        Assertions.assertEquals(true, model.properties().isNotification());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ApiOperationInner model =
            new ApiOperationInner()
                .withLocation("rhgfgrwsdpgrat")
                .withTags(mapOf("tbrxkjz", "bglbyvict"))
                .withProperties(
                    new ApiOperationPropertiesDefinition()
                        .withSummary("crwnamikz")
                        .withDescription("rqbsmswziq")
                        .withVisibility("uhok")
                        .withTrigger("uswhvhczznvfbycj")
                        .withTriggerHint("jww")
                        .withPageable(false)
                        .withAnnotation(
                            new ApiOperationAnnotation()
                                .withStatus(StatusAnnotation.PRODUCTION)
                                .withFamily("mxqhndvnoamldse")
                                .withRevision(757674973))
                        .withApi(
                            new ApiReference()
                                .withId("jxgrytfmp")
                                .withDisplayName("jhhflzokxcoxpel")
                                .withDescription("eta")
                                .withIconUri("tsxoatftgz")
                                .withSwagger("datapbswvefloccsrm")
                                .withBrandColor("ihmipgawtxxpk")
                                .withCategory(ApiTier.ENTERPRISE))
                        .withInputsDefinition(
                            new SwaggerSchema()
                                .withRef("sxwpndfcpfnznthj")
                                .withType(SwaggerSchemaType.ARRAY)
                                .withTitle("aosrxuz")
                                .withProperties(mapOf())
                                .withAdditionalProperties("datatcqiosmg")
                                .withRequired(Arrays.asList("hgxqdlyrt"))
                                .withMaxProperties(1395240119)
                                .withMinProperties(1207398584)
                                .withAllOf(Arrays.asList())
                                .withDiscriminator("zkatb")
                                .withReadOnly(true)
                                .withExample("databsoqeqala")
                                .withNotificationUrlExtension(false))
                        .withResponsesDefinition(
                            mapOf(
                                "kpak",
                                new SwaggerSchema()
                                    .withRef("febwlnbmhyreeudz")
                                    .withType(SwaggerSchemaType.NULL)
                                    .withTitle("pdqmjxlyyzglgouw")
                                    .withProperties(mapOf())
                                    .withAdditionalProperties("datajyuojqtobaxkjeyt")
                                    .withRequired(Arrays.asList())
                                    .withMaxProperties(1073974691)
                                    .withMinProperties(254445190)
                                    .withAllOf(Arrays.asList())
                                    .withDiscriminator("rusnk")
                                    .withReadOnly(false)
                                    .withExample("dataqunjqh")
                                    .withNotificationUrlExtension(false),
                                "saasiixtmkzj",
                                new SwaggerSchema()
                                    .withRef("ifmjnn")
                                    .withType(SwaggerSchemaType.FILE)
                                    .withTitle("abpxuc")
                                    .withProperties(mapOf())
                                    .withAdditionalProperties("dataqoweyirdhl")
                                    .withRequired(Arrays.asList())
                                    .withMaxProperties(1189308614)
                                    .withMinProperties(351115849)
                                    .withAllOf(Arrays.asList())
                                    .withDiscriminator("qmp")
                                    .withReadOnly(true)
                                    .withExample("datapqxpx")
                                    .withNotificationUrlExtension(false)))
                        .withIsWebhook(true)
                        .withIsNotification(true));
        model = BinaryData.fromObject(model).toObject(ApiOperationInner.class);
        Assertions.assertEquals("rhgfgrwsdpgrat", model.location());
        Assertions.assertEquals("bglbyvict", model.tags().get("tbrxkjz"));
        Assertions.assertEquals("crwnamikz", model.properties().summary());
        Assertions.assertEquals("rqbsmswziq", model.properties().description());
        Assertions.assertEquals("uhok", model.properties().visibility());
        Assertions.assertEquals("uswhvhczznvfbycj", model.properties().trigger());
        Assertions.assertEquals("jww", model.properties().triggerHint());
        Assertions.assertEquals(false, model.properties().pageable());
        Assertions.assertEquals(StatusAnnotation.PRODUCTION, model.properties().annotation().status());
        Assertions.assertEquals("mxqhndvnoamldse", model.properties().annotation().family());
        Assertions.assertEquals(757674973, model.properties().annotation().revision());
        Assertions.assertEquals("jxgrytfmp", model.properties().api().id());
        Assertions.assertEquals("jhhflzokxcoxpel", model.properties().api().displayName());
        Assertions.assertEquals("eta", model.properties().api().description());
        Assertions.assertEquals("tsxoatftgz", model.properties().api().iconUri());
        Assertions.assertEquals("ihmipgawtxxpk", model.properties().api().brandColor());
        Assertions.assertEquals(ApiTier.ENTERPRISE, model.properties().api().category());
        Assertions.assertEquals("sxwpndfcpfnznthj", model.properties().inputsDefinition().ref());
        Assertions.assertEquals(SwaggerSchemaType.ARRAY, model.properties().inputsDefinition().type());
        Assertions.assertEquals("aosrxuz", model.properties().inputsDefinition().title());
        Assertions.assertEquals("hgxqdlyrt", model.properties().inputsDefinition().required().get(0));
        Assertions.assertEquals(1395240119, model.properties().inputsDefinition().maxProperties());
        Assertions.assertEquals(1207398584, model.properties().inputsDefinition().minProperties());
        Assertions.assertEquals("zkatb", model.properties().inputsDefinition().discriminator());
        Assertions.assertEquals(true, model.properties().inputsDefinition().readOnly());
        Assertions.assertEquals(false, model.properties().inputsDefinition().notificationUrlExtension());
        Assertions.assertEquals("febwlnbmhyreeudz", model.properties().responsesDefinition().get("kpak").ref());
        Assertions.assertEquals(SwaggerSchemaType.NULL, model.properties().responsesDefinition().get("kpak").type());
        Assertions.assertEquals("pdqmjxlyyzglgouw", model.properties().responsesDefinition().get("kpak").title());
        Assertions.assertEquals(1073974691, model.properties().responsesDefinition().get("kpak").maxProperties());
        Assertions.assertEquals(254445190, model.properties().responsesDefinition().get("kpak").minProperties());
        Assertions.assertEquals("rusnk", model.properties().responsesDefinition().get("kpak").discriminator());
        Assertions.assertEquals(false, model.properties().responsesDefinition().get("kpak").readOnly());
        Assertions.assertEquals(false, model.properties().responsesDefinition().get("kpak").notificationUrlExtension());
        Assertions.assertEquals(true, model.properties().isWebhook());
        Assertions.assertEquals(true, model.properties().isNotification());
    }

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