// 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.Identity;
import com.azure.resourcemanager.agrifood.models.PublicNetworkAccess;
import com.azure.resourcemanager.agrifood.models.ResourceIdentityType;
import com.azure.resourcemanager.agrifood.models.SensorIntegration;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class FarmBeatsInnerTests {
    @Test
    public void testDeserialize() {
        FarmBeatsInner model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"principalId\":\"akeqs\",\"tenantId\":\"yb\",\"type\":\"SystemAssigned\"},\"properties\":{\"instanceUri\":\"qytbciq\",\"provisioningState\":\"Updating\",\"sensorIntegration\":{\"enabled\":\"mmnkzsmodmgl\",\"provisioningState\":\"Deleting\"},\"publicNetworkAccess\":\"Hybrid\",\"privateEndpointConnections\":{\"id\":\"utduqktapspwgcu\",\"name\":\"rtumkdosvq\",\"type\":\"hbmdgbbjfdd\"}},\"location\":\"mbmbexppbh\",\"tags\":{\"algbquxigjyjg\":\"rolfpfp\",\"lnerkujysvleju\":\"jaoyfhrtx\"},\"id\":\"fqawrlyxw\",\"name\":\"kcprbnw\",\"type\":\"xgjvtbv\"}")
                .toObject(FarmBeatsInner.class);
        Assertions.assertEquals("mbmbexppbh", model.location());
        Assertions.assertEquals("rolfpfp", model.tags().get("algbquxigjyjg"));
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals("mmnkzsmodmgl", model.sensorIntegration().enabled());
        Assertions.assertEquals(PublicNetworkAccess.HYBRID, model.publicNetworkAccess());
    }

    @Test
    public void testSerialize() {
        FarmBeatsInner model =
            new FarmBeatsInner()
                .withLocation("mbmbexppbh")
                .withTags(mapOf("algbquxigjyjg", "rolfpfp", "lnerkujysvleju", "jaoyfhrtx"))
                .withIdentity(new Identity().withType(ResourceIdentityType.SYSTEM_ASSIGNED))
                .withSensorIntegration(new SensorIntegration().withEnabled("mmnkzsmodmgl"))
                .withPublicNetworkAccess(PublicNetworkAccess.HYBRID);
        model = BinaryData.fromObject(model).toObject(FarmBeatsInner.class);
        Assertions.assertEquals("mbmbexppbh", model.location());
        Assertions.assertEquals("rolfpfp", model.tags().get("algbquxigjyjg"));
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals("mmnkzsmodmgl", model.sensorIntegration().enabled());
        Assertions.assertEquals(PublicNetworkAccess.HYBRID, model.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;
    }
}
