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

package com.azure.resourcemanager.subscription.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.subscription.fluent.models.SubscriptionInner;
import com.azure.resourcemanager.subscription.models.SubscriptionListResult;
import com.azure.resourcemanager.subscription.models.SubscriptionPolicies;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SubscriptionListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SubscriptionListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"id\":\"h\",\"subscriptionId\":\"cnyejhkryhtnapcz\",\"displayName\":\"okjye\",\"state\":\"Disabled\",\"tenantId\":\"ni\",\"tags\":{\"odmailzyd\":\"xzjnchgejs\",\"jwyahuxinpmqnja\":\"h\",\"tegjvwmf\":\"wixjsprozvcp\",\"pjhulsuuvmkj\":\"atscmd\"},\"subscriptionPolicies\":{\"locationPlacementId\":\"rwfndiod\",\"quotaId\":\"slwejdpvw\",\"spendingLimit\":\"CurrentPeriodOff\"},\"authorizationSource\":\"psoacctazakljl\"},{\"id\":\"bcryffdfd\",\"subscriptionId\":\"ygexpaojakhmsb\",\"displayName\":\"hcrzevd\",\"state\":\"Disabled\",\"tenantId\":\"aolthqtrg\",\"tags\":{\"rwzoxxjtfelluwf\":\"pfzfsinzgvfc\"},\"subscriptionPolicies\":{\"locationPlacementId\":\"onpeqfpjkjlxofp\",\"quotaId\":\"hpf\",\"spendingLimit\":\"On\"},\"authorizationSource\":\"ininmay\"},{\"id\":\"ybb\",\"subscriptionId\":\"odepoogin\",\"displayName\":\"amiheognarxz\",\"state\":\"Enabled\",\"tenantId\":\"o\",\"tags\":{\"bwjzr\":\"ivyevcciqihnhun\"},\"subscriptionPolicies\":{\"locationPlacementId\":\"gxg\",\"quotaId\":\"pemvtzfkufubljof\",\"spendingLimit\":\"On\"},\"authorizationSource\":\"fjaeq\"},{\"id\":\"qjbasvms\",\"subscriptionId\":\"qulngsntnbybkzgc\",\"displayName\":\"wclxxwrl\",\"state\":\"Warned\",\"tenantId\":\"skcqvkocrcjd\",\"tags\":{\"bnjbiksqrglssain\":\"nh\",\"wnzlljfmppeeb\":\"p\"},\"subscriptionPolicies\":{\"locationPlacementId\":\"xsabkyqdu\",\"quotaId\":\"itcjczdz\",\"spendingLimit\":\"On\"},\"authorizationSource\":\"hkr\"}],\"nextLink\":\"d\"}")
                .toObject(SubscriptionListResult.class);
        Assertions.assertEquals("xzjnchgejs", model.value().get(0).tags().get("odmailzyd"));
        Assertions.assertEquals("psoacctazakljl", model.value().get(0).authorizationSource());
        Assertions.assertEquals("d", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SubscriptionListResult model =
            new SubscriptionListResult()
                .withValue(
                    Arrays
                        .asList(
                            new SubscriptionInner()
                                .withTags(
                                    mapOf(
                                        "odmailzyd",
                                        "xzjnchgejs",
                                        "jwyahuxinpmqnja",
                                        "h",
                                        "tegjvwmf",
                                        "wixjsprozvcp",
                                        "pjhulsuuvmkj",
                                        "atscmd"))
                                .withSubscriptionPolicies(new SubscriptionPolicies())
                                .withAuthorizationSource("psoacctazakljl"),
                            new SubscriptionInner()
                                .withTags(mapOf("rwzoxxjtfelluwf", "pfzfsinzgvfc"))
                                .withSubscriptionPolicies(new SubscriptionPolicies())
                                .withAuthorizationSource("ininmay"),
                            new SubscriptionInner()
                                .withTags(mapOf("bwjzr", "ivyevcciqihnhun"))
                                .withSubscriptionPolicies(new SubscriptionPolicies())
                                .withAuthorizationSource("fjaeq"),
                            new SubscriptionInner()
                                .withTags(mapOf("bnjbiksqrglssain", "nh", "wnzlljfmppeeb", "p"))
                                .withSubscriptionPolicies(new SubscriptionPolicies())
                                .withAuthorizationSource("hkr")))
                .withNextLink("d");
        model = BinaryData.fromObject(model).toObject(SubscriptionListResult.class);
        Assertions.assertEquals("xzjnchgejs", model.value().get(0).tags().get("odmailzyd"));
        Assertions.assertEquals("psoacctazakljl", model.value().get(0).authorizationSource());
        Assertions.assertEquals("d", model.nextLink());
    }

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