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

package com.azure.resourcemanager.security.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.security.fluent.models.PricingInner;
import com.azure.resourcemanager.security.models.Extension;
import com.azure.resourcemanager.security.models.IsEnabled;
import com.azure.resourcemanager.security.models.PricingTier;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class PricingInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        PricingInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"pricingTier\":\"Standard\",\"subPlan\":\"dqytbciqfouflmm\",\"freeTrialRemainingTime\":\"PT108H50M46S\",\"enablementTime\":\"2021-02-23T09:34:26Z\",\"deprecated\":false,\"replacedBy\":[\"lougpbkw\",\"mutduqktaps\"],\"extensions\":[{\"name\":\"cuertu\",\"isEnabled\":\"True\",\"additionalExtensionProperties\":{}}]},\"id\":\"svqwhbmdgbbjfd\",\"name\":\"gmbmbexppbh\",\"type\":\"q\"}")
                .toObject(PricingInner.class);
        Assertions.assertEquals(PricingTier.STANDARD, model.pricingTier());
        Assertions.assertEquals("dqytbciqfouflmm", model.subPlan());
        Assertions.assertEquals("cuertu", model.extensions().get(0).name());
        Assertions.assertEquals(IsEnabled.TRUE, model.extensions().get(0).isEnabled());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        PricingInner model =
            new PricingInner()
                .withPricingTier(PricingTier.STANDARD)
                .withSubPlan("dqytbciqfouflmm")
                .withExtensions(
                    Arrays
                        .asList(
                            new Extension()
                                .withName("cuertu")
                                .withIsEnabled(IsEnabled.TRUE)
                                .withAdditionalExtensionProperties(mapOf())));
        model = BinaryData.fromObject(model).toObject(PricingInner.class);
        Assertions.assertEquals(PricingTier.STANDARD, model.pricingTier());
        Assertions.assertEquals("dqytbciqfouflmm", model.subPlan());
        Assertions.assertEquals("cuertu", model.extensions().get(0).name());
        Assertions.assertEquals(IsEnabled.TRUE, model.extensions().get(0).isEnabled());
    }

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