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

package com.azure.resourcemanager.managedapplications.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.managedapplications.fluent.models.ApplicationDefinitionInner;
import com.azure.resourcemanager.managedapplications.models.ApplicationArtifact;
import com.azure.resourcemanager.managedapplications.models.ApplicationArtifactType;
import com.azure.resourcemanager.managedapplications.models.ApplicationLockLevel;
import com.azure.resourcemanager.managedapplications.models.ApplicationProviderAuthorization;
import com.azure.resourcemanager.managedapplications.models.Identity;
import com.azure.resourcemanager.managedapplications.models.ResourceIdentityType;
import com.azure.resourcemanager.managedapplications.models.Sku;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ApplicationDefinitionInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ApplicationDefinitionInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"lockLevel\":\"CanNotDelete\",\"displayName\":\"pdappds\",\"isEnabled\":\"kvwrwjfeu\",\"authorizations\":[{\"principalId\":\"hutje\",\"roleDefinitionId\":\"tmrldhugjzzdatq\"},{\"principalId\":\"hocdgeab\",\"roleDefinitionId\":\"gphuticndvka\"},{\"principalId\":\"zwyiftyhxhur\",\"roleDefinitionId\":\"k\"},{\"principalId\":\"tyxolniwpwc\",\"roleDefinitionId\":\"kjfkg\"}],\"artifacts\":[{\"name\":\"klryplwck\",\"uri\":\"syyp\",\"type\":\"Template\"}],\"description\":\"sgcbac\",\"packageFileUri\":\"ejk\",\"mainTemplate\":\"dataynqgoulzndlikwyq\",\"createUiDefinition\":\"datafgibmadgakeq\"},\"managedBy\":\"xybz\",\"sku\":{\"name\":\"e\",\"tier\":\"ytb\",\"size\":\"qfou\",\"family\":\"mmnkzsmodmgl\",\"model\":\"gpbkwtmut\",\"capacity\":1581209984},\"identity\":{\"principalId\":\"ap\",\"tenantId\":\"wgcu\",\"type\":\"SystemAssigned\"},\"location\":\"umkdosvqwhbmd\",\"tags\":{\"ppbhtqqrolfp\":\"jfddgmbmbe\"},\"id\":\"psalgbqux\",\"name\":\"gjyjgzjaoyfhrtxi\",\"type\":\"n\"}")
                .toObject(ApplicationDefinitionInner.class);
        Assertions.assertEquals("umkdosvqwhbmd", model.location());
        Assertions.assertEquals("jfddgmbmbe", model.tags().get("ppbhtqqrolfp"));
        Assertions.assertEquals("xybz", model.managedBy());
        Assertions.assertEquals("e", model.sku().name());
        Assertions.assertEquals("ytb", model.sku().tier());
        Assertions.assertEquals("qfou", model.sku().size());
        Assertions.assertEquals("mmnkzsmodmgl", model.sku().family());
        Assertions.assertEquals("gpbkwtmut", model.sku().model());
        Assertions.assertEquals(1581209984, model.sku().capacity());
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals(ApplicationLockLevel.CAN_NOT_DELETE, model.lockLevel());
        Assertions.assertEquals("pdappds", model.displayName());
        Assertions.assertEquals("kvwrwjfeu", model.isEnabled());
        Assertions.assertEquals("hutje", model.authorizations().get(0).principalId());
        Assertions.assertEquals("tmrldhugjzzdatq", model.authorizations().get(0).roleDefinitionId());
        Assertions.assertEquals("klryplwck", model.artifacts().get(0).name());
        Assertions.assertEquals("syyp", model.artifacts().get(0).uri());
        Assertions.assertEquals(ApplicationArtifactType.TEMPLATE, model.artifacts().get(0).type());
        Assertions.assertEquals("sgcbac", model.description());
        Assertions.assertEquals("ejk", model.packageFileUri());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ApplicationDefinitionInner model =
            new ApplicationDefinitionInner()
                .withLocation("umkdosvqwhbmd")
                .withTags(mapOf("ppbhtqqrolfp", "jfddgmbmbe"))
                .withManagedBy("xybz")
                .withSku(
                    new Sku()
                        .withName("e")
                        .withTier("ytb")
                        .withSize("qfou")
                        .withFamily("mmnkzsmodmgl")
                        .withModel("gpbkwtmut")
                        .withCapacity(1581209984))
                .withIdentity(new Identity().withType(ResourceIdentityType.SYSTEM_ASSIGNED))
                .withLockLevel(ApplicationLockLevel.CAN_NOT_DELETE)
                .withDisplayName("pdappds")
                .withIsEnabled("kvwrwjfeu")
                .withAuthorizations(
                    Arrays
                        .asList(
                            new ApplicationProviderAuthorization()
                                .withPrincipalId("hutje")
                                .withRoleDefinitionId("tmrldhugjzzdatq"),
                            new ApplicationProviderAuthorization()
                                .withPrincipalId("hocdgeab")
                                .withRoleDefinitionId("gphuticndvka"),
                            new ApplicationProviderAuthorization()
                                .withPrincipalId("zwyiftyhxhur")
                                .withRoleDefinitionId("k"),
                            new ApplicationProviderAuthorization()
                                .withPrincipalId("tyxolniwpwc")
                                .withRoleDefinitionId("kjfkg")))
                .withArtifacts(
                    Arrays
                        .asList(
                            new ApplicationArtifact()
                                .withName("klryplwck")
                                .withUri("syyp")
                                .withType(ApplicationArtifactType.TEMPLATE)))
                .withDescription("sgcbac")
                .withPackageFileUri("ejk")
                .withMainTemplate("dataynqgoulzndlikwyq")
                .withCreateUiDefinition("datafgibmadgakeq");
        model = BinaryData.fromObject(model).toObject(ApplicationDefinitionInner.class);
        Assertions.assertEquals("umkdosvqwhbmd", model.location());
        Assertions.assertEquals("jfddgmbmbe", model.tags().get("ppbhtqqrolfp"));
        Assertions.assertEquals("xybz", model.managedBy());
        Assertions.assertEquals("e", model.sku().name());
        Assertions.assertEquals("ytb", model.sku().tier());
        Assertions.assertEquals("qfou", model.sku().size());
        Assertions.assertEquals("mmnkzsmodmgl", model.sku().family());
        Assertions.assertEquals("gpbkwtmut", model.sku().model());
        Assertions.assertEquals(1581209984, model.sku().capacity());
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals(ApplicationLockLevel.CAN_NOT_DELETE, model.lockLevel());
        Assertions.assertEquals("pdappds", model.displayName());
        Assertions.assertEquals("kvwrwjfeu", model.isEnabled());
        Assertions.assertEquals("hutje", model.authorizations().get(0).principalId());
        Assertions.assertEquals("tmrldhugjzzdatq", model.authorizations().get(0).roleDefinitionId());
        Assertions.assertEquals("klryplwck", model.artifacts().get(0).name());
        Assertions.assertEquals("syyp", model.artifacts().get(0).uri());
        Assertions.assertEquals(ApplicationArtifactType.TEMPLATE, model.artifacts().get(0).type());
        Assertions.assertEquals("sgcbac", model.description());
        Assertions.assertEquals("ejk", model.packageFileUri());
    }

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