// 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.IntegrationServiceEnvironmentInner;
import com.azure.resourcemanager.logic.models.FlowEndpointsConfiguration;
import com.azure.resourcemanager.logic.models.IntegrationServiceEnvironmenEncryptionConfiguration;
import com.azure.resourcemanager.logic.models.IntegrationServiceEnvironmentProperties;
import com.azure.resourcemanager.logic.models.IntegrationServiceEnvironmentSku;
import com.azure.resourcemanager.logic.models.IntegrationServiceEnvironmentSkuName;
import com.azure.resourcemanager.logic.models.ManagedServiceIdentity;
import com.azure.resourcemanager.logic.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.logic.models.NetworkConfiguration;
import com.azure.resourcemanager.logic.models.UserAssignedIdentity;
import com.azure.resourcemanager.logic.models.WorkflowProvisioningState;
import com.azure.resourcemanager.logic.models.WorkflowState;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class IntegrationServiceEnvironmentInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        IntegrationServiceEnvironmentInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"provisioningState\":\"NotSpecified\",\"state\":\"Disabled\",\"integrationServiceEnvironmentId\":\"eammxqiekkkzddr\",\"endpointsConfiguration\":{},\"networkConfiguration\":{\"virtualNetworkAddressSpace\":\"bmxva\",\"subnets\":[]},\"encryptionConfiguration\":{}},\"sku\":{\"name\":\"Developer\",\"capacity\":1645748788},\"identity\":{\"type\":\"None\",\"tenantId\":\"f6abc3a4-dd32-478b-9dc7-1ce7d4eb9f1c\",\"principalId\":\"193d5476-6780-4787-8d11-41e15787d9c3\",\"userAssignedIdentities\":{\"ibabxvititvtzeex\":{\"principalId\":\"s\",\"clientId\":\"prtujwsawdd\"}}},\"location\":\"vo\",\"tags\":{\"gsfjac\":\"glecdmdqbwpypq\",\"d\":\"slhhxudbxv\",\"ud\":\"tnsi\"},\"id\":\"z\",\"name\":\"mes\",\"type\":\"kdlpa\"}")
                .toObject(IntegrationServiceEnvironmentInner.class);
        Assertions.assertEquals("vo", model.location());
        Assertions.assertEquals("glecdmdqbwpypq", model.tags().get("gsfjac"));
        Assertions.assertEquals(WorkflowProvisioningState.NOT_SPECIFIED, model.properties().provisioningState());
        Assertions.assertEquals(WorkflowState.DISABLED, model.properties().state());
        Assertions.assertEquals("eammxqiekkkzddr", model.properties().integrationServiceEnvironmentId());
        Assertions.assertEquals("bmxva", model.properties().networkConfiguration().virtualNetworkAddressSpace());
        Assertions.assertEquals(IntegrationServiceEnvironmentSkuName.DEVELOPER, model.sku().name());
        Assertions.assertEquals(1645748788, model.sku().capacity());
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.identity().type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IntegrationServiceEnvironmentInner model =
            new IntegrationServiceEnvironmentInner()
                .withLocation("vo")
                .withTags(mapOf("gsfjac", "glecdmdqbwpypq", "d", "slhhxudbxv", "ud", "tnsi"))
                .withProperties(
                    new IntegrationServiceEnvironmentProperties()
                        .withProvisioningState(WorkflowProvisioningState.NOT_SPECIFIED)
                        .withState(WorkflowState.DISABLED)
                        .withIntegrationServiceEnvironmentId("eammxqiekkkzddr")
                        .withEndpointsConfiguration(new FlowEndpointsConfiguration())
                        .withNetworkConfiguration(
                            new NetworkConfiguration()
                                .withVirtualNetworkAddressSpace("bmxva")
                                .withSubnets(Arrays.asList()))
                        .withEncryptionConfiguration(new IntegrationServiceEnvironmenEncryptionConfiguration()))
                .withSku(
                    new IntegrationServiceEnvironmentSku()
                        .withName(IntegrationServiceEnvironmentSkuName.DEVELOPER)
                        .withCapacity(1645748788))
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.NONE)
                        .withUserAssignedIdentities(mapOf("ibabxvititvtzeex", new UserAssignedIdentity())));
        model = BinaryData.fromObject(model).toObject(IntegrationServiceEnvironmentInner.class);
        Assertions.assertEquals("vo", model.location());
        Assertions.assertEquals("glecdmdqbwpypq", model.tags().get("gsfjac"));
        Assertions.assertEquals(WorkflowProvisioningState.NOT_SPECIFIED, model.properties().provisioningState());
        Assertions.assertEquals(WorkflowState.DISABLED, model.properties().state());
        Assertions.assertEquals("eammxqiekkkzddr", model.properties().integrationServiceEnvironmentId());
        Assertions.assertEquals("bmxva", model.properties().networkConfiguration().virtualNetworkAddressSpace());
        Assertions.assertEquals(IntegrationServiceEnvironmentSkuName.DEVELOPER, model.sku().name());
        Assertions.assertEquals(1645748788, model.sku().capacity());
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.identity().type());
    }

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