// 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.models.FarmBeatsUpdateProperties;
import com.azure.resourcemanager.agrifood.models.FarmBeatsUpdateRequestModel;
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 FarmBeatsUpdateRequestModelTests {
    @Test
    public void testDeserialize() {
        FarmBeatsUpdateRequestModel model =
            BinaryData
                .fromString(
                    "{\"location\":\"ysh\",\"identity\":{\"principalId\":\"afbljjgpbtoqcjmk\",\"tenantId\":\"a\",\"type\":\"SystemAssigned\"},\"properties\":{\"sensorIntegration\":{\"enabled\":\"qajzyulpkudjkr\",\"provisioningState\":\"Creating\"},\"publicNetworkAccess\":\"Hybrid\"},\"tags\":{\"xzlocxscp\":\"pgzgq\",\"j\":\"ierhhbcsglummaj\",\"jionpimexgstxgc\":\"odxobnbdxkqpxok\"}}")
                .toObject(FarmBeatsUpdateRequestModel.class);
        Assertions.assertEquals("ysh", model.location());
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals("qajzyulpkudjkr", model.properties().sensorIntegration().enabled());
        Assertions.assertEquals(PublicNetworkAccess.HYBRID, model.properties().publicNetworkAccess());
        Assertions.assertEquals("pgzgq", model.tags().get("xzlocxscp"));
    }

    @Test
    public void testSerialize() {
        FarmBeatsUpdateRequestModel model =
            new FarmBeatsUpdateRequestModel()
                .withLocation("ysh")
                .withIdentity(new Identity().withType(ResourceIdentityType.SYSTEM_ASSIGNED))
                .withProperties(
                    new FarmBeatsUpdateProperties()
                        .withSensorIntegration(new SensorIntegration().withEnabled("qajzyulpkudjkr"))
                        .withPublicNetworkAccess(PublicNetworkAccess.HYBRID))
                .withTags(mapOf("xzlocxscp", "pgzgq", "j", "ierhhbcsglummaj", "jionpimexgstxgc", "odxobnbdxkqpxok"));
        model = BinaryData.fromObject(model).toObject(FarmBeatsUpdateRequestModel.class);
        Assertions.assertEquals("ysh", model.location());
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.identity().type());
        Assertions.assertEquals("qajzyulpkudjkr", model.properties().sensorIntegration().enabled());
        Assertions.assertEquals(PublicNetworkAccess.HYBRID, model.properties().publicNetworkAccess());
        Assertions.assertEquals("pgzgq", model.tags().get("xzlocxscp"));
    }

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