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

package com.azure.resourcemanager.agrifood.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.agrifood.fluent.models.FarmBeatsInner;
import com.azure.resourcemanager.agrifood.models.FarmBeatsListResponse;
import com.azure.resourcemanager.agrifood.models.Identity;
import com.azure.resourcemanager.agrifood.models.PublicNetworkAccess;
import com.azure.resourcemanager.agrifood.models.ResourceIdentityType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class FarmBeatsListResponseTests {
    @Test
    public void testDeserialize() {
        FarmBeatsListResponse model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"identity\":{\"principalId\":\"clwhijcoejctbz\",\"tenantId\":\"s\",\"type\":\"SystemAssigned\"},\"properties\":{\"instanceUri\":\"kbfkg\",\"provisioningState\":\"Succeeded\",\"publicNetworkAccess\":\"Enabled\"},\"location\":\"ppofmxaxcfjpgdd\",\"tags\":{\"exhd\":\"jjxhvpmo\"},\"id\":\"xibqeojnx\",\"name\":\"bzv\",\"type\":\"dntwndeicbtw\"},{\"identity\":{\"principalId\":\"aoqvuh\",\"tenantId\":\"cffcyddglmj\",\"type\":\"SystemAssigned\"},\"properties\":{\"instanceUri\":\"wpyeicxmqciwqvh\",\"provisioningState\":\"Updating\",\"publicNetworkAccess\":\"Hybrid\"},\"location\":\"dtopbob\",\"tags\":{\"w\":\"hm\",\"a\":\"a\"},\"id\":\"hrzayvvtpgvdf\",\"name\":\"iotkftutqxl\",\"type\":\"gxlefgugnxkrxd\"},{\"identity\":{\"principalId\":\"dt\",\"tenantId\":\"zrvqdr\",\"type\":\"SystemAssigned\"},\"properties\":{\"instanceUri\":\"big\",\"provisioningState\":\"Failed\",\"publicNetworkAccess\":\"Enabled\"},\"location\":\"wska\",\"tags\":{\"rvynhzgpph\":\"tzlcuiywgqywgn\",\"m\":\"cgyncocpecf\",\"bmqj\":\"coofsxlzev\"},\"id\":\"abcypmivk\",\"name\":\"lzu\",\"type\":\"ccfwnfnbacfion\"},{\"identity\":{\"principalId\":\"x\",\"tenantId\":\"qgtz\",\"type\":\"SystemAssigned\"},\"properties\":{\"instanceUri\":\"bqqwxrj\",\"provisioningState\":\"Deleting\",\"publicNetworkAccess\":\"Hybrid\"},\"location\":\"sub\",\"tags\":{\"ochcbonqvpkvl\":\"jampmngnzscxaqw\",\"ase\":\"xnj\"},\"id\":\"pheoflokeyy\",\"name\":\"enjbdlwtgrhp\",\"type\":\"jp\"}],\"nextLink\":\"masxazjpqyegu\"}")
                .toObject(FarmBeatsListResponse.class);
        Assertions.assertEquals("ppofmxaxcfjpgdd", model.value().get(0).location());
        Assertions.assertEquals("jjxhvpmo", model.value().get(0).tags().get("exhd"));
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
    }

    @Test
    public void testSerialize() {
        FarmBeatsListResponse model =
            new FarmBeatsListResponse()
                .withValue(
                    Arrays
                        .asList(
                            new FarmBeatsInner()
                                .withLocation("ppofmxaxcfjpgdd")
                                .withTags(mapOf("exhd", "jjxhvpmo"))
                                .withIdentity(new Identity().withType(ResourceIdentityType.SYSTEM_ASSIGNED))
                                .withPublicNetworkAccess(PublicNetworkAccess.ENABLED),
                            new FarmBeatsInner()
                                .withLocation("dtopbob")
                                .withTags(mapOf("w", "hm", "a", "a"))
                                .withIdentity(new Identity().withType(ResourceIdentityType.SYSTEM_ASSIGNED))
                                .withPublicNetworkAccess(PublicNetworkAccess.HYBRID),
                            new FarmBeatsInner()
                                .withLocation("wska")
                                .withTags(
                                    mapOf("rvynhzgpph", "tzlcuiywgqywgn", "m", "cgyncocpecf", "bmqj", "coofsxlzev"))
                                .withIdentity(new Identity().withType(ResourceIdentityType.SYSTEM_ASSIGNED))
                                .withPublicNetworkAccess(PublicNetworkAccess.ENABLED),
                            new FarmBeatsInner()
                                .withLocation("sub")
                                .withTags(mapOf("ochcbonqvpkvl", "jampmngnzscxaqw", "ase", "xnj"))
                                .withIdentity(new Identity().withType(ResourceIdentityType.SYSTEM_ASSIGNED))
                                .withPublicNetworkAccess(PublicNetworkAccess.HYBRID)));
        model = BinaryData.fromObject(model).toObject(FarmBeatsListResponse.class);
        Assertions.assertEquals("ppofmxaxcfjpgdd", model.value().get(0).location());
        Assertions.assertEquals("jjxhvpmo", model.value().get(0).tags().get("exhd"));
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
    }

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