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

package com.azure.resourcemanager.mariadb.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.mariadb.models.GeoRedundantBackup;
import com.azure.resourcemanager.mariadb.models.MinimalTlsVersionEnum;
import com.azure.resourcemanager.mariadb.models.PublicNetworkAccessEnum;
import com.azure.resourcemanager.mariadb.models.ServerForCreate;
import com.azure.resourcemanager.mariadb.models.ServerPropertiesForCreate;
import com.azure.resourcemanager.mariadb.models.ServerVersion;
import com.azure.resourcemanager.mariadb.models.Sku;
import com.azure.resourcemanager.mariadb.models.SkuTier;
import com.azure.resourcemanager.mariadb.models.SslEnforcementEnum;
import com.azure.resourcemanager.mariadb.models.StorageAutogrow;
import com.azure.resourcemanager.mariadb.models.StorageProfile;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ServerForCreateTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ServerForCreate model =
            BinaryData
                .fromString(
                    "{\"sku\":{\"name\":\"mhquvgjxp\",\"tier\":\"MemoryOptimized\",\"capacity\":128065962,\"size\":\"hmtzopbsphrup\",\"family\":\"gsybbejhp\"},\"properties\":{\"createMode\":\"ServerPropertiesForCreate\",\"version\":\"10.2\",\"sslEnforcement\":\"Enabled\",\"minimalTlsVersion\":\"TLSEnforcementDisabled\",\"publicNetworkAccess\":\"Disabled\",\"storageProfile\":{\"backupRetentionDays\":212195195,\"geoRedundantBackup\":\"Enabled\",\"storageMB\":1540848477,\"storageAutogrow\":\"Enabled\"}},\"location\":\"oqjzehtbmufpowno\",\"tags\":{\"soqijg\":\"wlrxyb\",\"rbt\":\"dmbpazlobcufpdz\"}}")
                .toObject(ServerForCreate.class);
        Assertions.assertEquals("mhquvgjxp", model.sku().name());
        Assertions.assertEquals(SkuTier.MEMORY_OPTIMIZED, model.sku().tier());
        Assertions.assertEquals(128065962, model.sku().capacity());
        Assertions.assertEquals("hmtzopbsphrup", model.sku().size());
        Assertions.assertEquals("gsybbejhp", model.sku().family());
        Assertions.assertEquals(ServerVersion.ONE_ZERO_TWO, model.properties().version());
        Assertions.assertEquals(SslEnforcementEnum.ENABLED, model.properties().sslEnforcement());
        Assertions.assertEquals(MinimalTlsVersionEnum.TLSENFORCEMENT_DISABLED, model.properties().minimalTlsVersion());
        Assertions.assertEquals(PublicNetworkAccessEnum.DISABLED, model.properties().publicNetworkAccess());
        Assertions.assertEquals(212195195, model.properties().storageProfile().backupRetentionDays());
        Assertions.assertEquals(GeoRedundantBackup.ENABLED, model.properties().storageProfile().geoRedundantBackup());
        Assertions.assertEquals(1540848477, model.properties().storageProfile().storageMB());
        Assertions.assertEquals(StorageAutogrow.ENABLED, model.properties().storageProfile().storageAutogrow());
        Assertions.assertEquals("oqjzehtbmufpowno", model.location());
        Assertions.assertEquals("wlrxyb", model.tags().get("soqijg"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ServerForCreate model =
            new ServerForCreate()
                .withSku(
                    new Sku()
                        .withName("mhquvgjxp")
                        .withTier(SkuTier.MEMORY_OPTIMIZED)
                        .withCapacity(128065962)
                        .withSize("hmtzopbsphrup")
                        .withFamily("gsybbejhp"))
                .withProperties(
                    new ServerPropertiesForCreate()
                        .withVersion(ServerVersion.ONE_ZERO_TWO)
                        .withSslEnforcement(SslEnforcementEnum.ENABLED)
                        .withMinimalTlsVersion(MinimalTlsVersionEnum.TLSENFORCEMENT_DISABLED)
                        .withPublicNetworkAccess(PublicNetworkAccessEnum.DISABLED)
                        .withStorageProfile(
                            new StorageProfile()
                                .withBackupRetentionDays(212195195)
                                .withGeoRedundantBackup(GeoRedundantBackup.ENABLED)
                                .withStorageMB(1540848477)
                                .withStorageAutogrow(StorageAutogrow.ENABLED)))
                .withLocation("oqjzehtbmufpowno")
                .withTags(mapOf("soqijg", "wlrxyb", "rbt", "dmbpazlobcufpdz"));
        model = BinaryData.fromObject(model).toObject(ServerForCreate.class);
        Assertions.assertEquals("mhquvgjxp", model.sku().name());
        Assertions.assertEquals(SkuTier.MEMORY_OPTIMIZED, model.sku().tier());
        Assertions.assertEquals(128065962, model.sku().capacity());
        Assertions.assertEquals("hmtzopbsphrup", model.sku().size());
        Assertions.assertEquals("gsybbejhp", model.sku().family());
        Assertions.assertEquals(ServerVersion.ONE_ZERO_TWO, model.properties().version());
        Assertions.assertEquals(SslEnforcementEnum.ENABLED, model.properties().sslEnforcement());
        Assertions.assertEquals(MinimalTlsVersionEnum.TLSENFORCEMENT_DISABLED, model.properties().minimalTlsVersion());
        Assertions.assertEquals(PublicNetworkAccessEnum.DISABLED, model.properties().publicNetworkAccess());
        Assertions.assertEquals(212195195, model.properties().storageProfile().backupRetentionDays());
        Assertions.assertEquals(GeoRedundantBackup.ENABLED, model.properties().storageProfile().geoRedundantBackup());
        Assertions.assertEquals(1540848477, model.properties().storageProfile().storageMB());
        Assertions.assertEquals(StorageAutogrow.ENABLED, model.properties().storageProfile().storageAutogrow());
        Assertions.assertEquals("oqjzehtbmufpowno", model.location());
        Assertions.assertEquals("wlrxyb", model.tags().get("soqijg"));
    }

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