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

package com.azure.resourcemanager.resourcemover.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.resourcemover.fluent.models.MoveCollectionInner;
import com.azure.resourcemanager.resourcemover.models.Identity;
import com.azure.resourcemanager.resourcemover.models.MoveCollectionProperties;
import com.azure.resourcemanager.resourcemover.models.ResourceIdentityType;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class MoveCollectionInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        MoveCollectionInner model =
            BinaryData
                .fromString(
                    "{\"etag\":\"mhquvgjxp\",\"identity\":{\"type\":\"SystemAssigned\",\"principalId\":\"ehmtzop\",\"tenantId\":\"phrupidgsybbejhp\"},\"properties\":{\"sourceRegion\":\"ycm\",\"targetRegion\":\"xaobhdxbmtqioqjz\",\"provisioningState\":\"Updating\",\"errors\":{}},\"location\":\"ufpo\",\"tags\":{\"qsoqijgkd\":\"izhwlrxy\"},\"id\":\"bpazlobcufpdzn\",\"name\":\"btcqq\",\"type\":\"nq\"}")
                .toObject(MoveCollectionInner.class);
        Assertions.assertEquals("ufpo", model.location());
        Assertions.assertEquals("izhwlrxy", model.tags().get("qsoqijgkd"));
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals("ehmtzop", model.identity().principalId());
        Assertions.assertEquals("phrupidgsybbejhp", model.identity().tenantId());
        Assertions.assertEquals("ycm", model.properties().sourceRegion());
        Assertions.assertEquals("xaobhdxbmtqioqjz", model.properties().targetRegion());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        MoveCollectionInner model =
            new MoveCollectionInner()
                .withLocation("ufpo")
                .withTags(mapOf("qsoqijgkd", "izhwlrxy"))
                .withIdentity(
                    new Identity()
                        .withType(ResourceIdentityType.SYSTEM_ASSIGNED)
                        .withPrincipalId("ehmtzop")
                        .withTenantId("phrupidgsybbejhp"))
                .withProperties(
                    new MoveCollectionProperties().withSourceRegion("ycm").withTargetRegion("xaobhdxbmtqioqjz"));
        model = BinaryData.fromObject(model).toObject(MoveCollectionInner.class);
        Assertions.assertEquals("ufpo", model.location());
        Assertions.assertEquals("izhwlrxy", model.tags().get("qsoqijgkd"));
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals("ehmtzop", model.identity().principalId());
        Assertions.assertEquals("phrupidgsybbejhp", model.identity().tenantId());
        Assertions.assertEquals("ycm", model.properties().sourceRegion());
        Assertions.assertEquals("xaobhdxbmtqioqjz", model.properties().targetRegion());
    }

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