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

package com.azure.resourcemanager.azurearcdata.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.azurearcdata.fluent.models.SqlServerInstanceInner;
import com.azure.resourcemanager.azurearcdata.models.ArcSqlServerLicenseType;
import com.azure.resourcemanager.azurearcdata.models.ConnectionStatus;
import com.azure.resourcemanager.azurearcdata.models.DefenderStatus;
import com.azure.resourcemanager.azurearcdata.models.EditionType;
import com.azure.resourcemanager.azurearcdata.models.SqlServerInstanceProperties;
import com.azure.resourcemanager.azurearcdata.models.SqlVersion;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SqlServerInstanceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SqlServerInstanceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"version\":\"SQL Server"
                        + " 2016\",\"edition\":\"Express\",\"containerResourceId\":\"walm\",\"createTime\":\"yoxa\",\"vCore\":\"dkzjancuxrh\",\"status\":\"Disconnected\",\"patchLevel\":\"avxbniwdjswztsdb\",\"collation\":\"nxytxh\",\"currentVersion\":\"xbzpfzab\",\"instanceName\":\"cuh\",\"tcpDynamicPorts\":\"tcty\",\"tcpStaticPorts\":\"klbb\",\"productId\":\"plwzbhvgyugu\",\"licenseType\":\"HADR\",\"azureDefenderStatusLastUpdated\":\"2021-10-31T02:07:56Z\",\"azureDefenderStatus\":\"Unprotected\",\"provisioningState\":\"xquk\"},\"location\":\"plgmgsxnk\",\"tags\":{\"lopwiyig\":\"deslp\"},\"id\":\"xpkd\",\"name\":\"zb\",\"type\":\"iuebbaumny\"}")
                .toObject(SqlServerInstanceInner.class);
        Assertions.assertEquals("plgmgsxnk", model.location());
        Assertions.assertEquals("deslp", model.tags().get("lopwiyig"));
        Assertions.assertEquals(SqlVersion.SQL_SERVER_2016, model.properties().version());
        Assertions.assertEquals(EditionType.EXPRESS, model.properties().edition());
        Assertions.assertEquals("walm", model.properties().containerResourceId());
        Assertions.assertEquals("dkzjancuxrh", model.properties().vCore());
        Assertions.assertEquals(ConnectionStatus.DISCONNECTED, model.properties().status());
        Assertions.assertEquals("avxbniwdjswztsdb", model.properties().patchLevel());
        Assertions.assertEquals("nxytxh", model.properties().collation());
        Assertions.assertEquals("xbzpfzab", model.properties().currentVersion());
        Assertions.assertEquals("cuh", model.properties().instanceName());
        Assertions.assertEquals("tcty", model.properties().tcpDynamicPorts());
        Assertions.assertEquals("klbb", model.properties().tcpStaticPorts());
        Assertions.assertEquals("plwzbhvgyugu", model.properties().productId());
        Assertions.assertEquals(ArcSqlServerLicenseType.HADR, model.properties().licenseType());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-10-31T02:07:56Z"), model.properties().azureDefenderStatusLastUpdated());
        Assertions.assertEquals(DefenderStatus.UNPROTECTED, model.properties().azureDefenderStatus());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SqlServerInstanceInner model =
            new SqlServerInstanceInner()
                .withLocation("plgmgsxnk")
                .withTags(mapOf("lopwiyig", "deslp"))
                .withProperties(
                    new SqlServerInstanceProperties()
                        .withVersion(SqlVersion.SQL_SERVER_2016)
                        .withEdition(EditionType.EXPRESS)
                        .withContainerResourceId("walm")
                        .withVCore("dkzjancuxrh")
                        .withStatus(ConnectionStatus.DISCONNECTED)
                        .withPatchLevel("avxbniwdjswztsdb")
                        .withCollation("nxytxh")
                        .withCurrentVersion("xbzpfzab")
                        .withInstanceName("cuh")
                        .withTcpDynamicPorts("tcty")
                        .withTcpStaticPorts("klbb")
                        .withProductId("plwzbhvgyugu")
                        .withLicenseType(ArcSqlServerLicenseType.HADR)
                        .withAzureDefenderStatusLastUpdated(OffsetDateTime.parse("2021-10-31T02:07:56Z"))
                        .withAzureDefenderStatus(DefenderStatus.UNPROTECTED));
        model = BinaryData.fromObject(model).toObject(SqlServerInstanceInner.class);
        Assertions.assertEquals("plgmgsxnk", model.location());
        Assertions.assertEquals("deslp", model.tags().get("lopwiyig"));
        Assertions.assertEquals(SqlVersion.SQL_SERVER_2016, model.properties().version());
        Assertions.assertEquals(EditionType.EXPRESS, model.properties().edition());
        Assertions.assertEquals("walm", model.properties().containerResourceId());
        Assertions.assertEquals("dkzjancuxrh", model.properties().vCore());
        Assertions.assertEquals(ConnectionStatus.DISCONNECTED, model.properties().status());
        Assertions.assertEquals("avxbniwdjswztsdb", model.properties().patchLevel());
        Assertions.assertEquals("nxytxh", model.properties().collation());
        Assertions.assertEquals("xbzpfzab", model.properties().currentVersion());
        Assertions.assertEquals("cuh", model.properties().instanceName());
        Assertions.assertEquals("tcty", model.properties().tcpDynamicPorts());
        Assertions.assertEquals("klbb", model.properties().tcpStaticPorts());
        Assertions.assertEquals("plwzbhvgyugu", model.properties().productId());
        Assertions.assertEquals(ArcSqlServerLicenseType.HADR, model.properties().licenseType());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-10-31T02:07:56Z"), model.properties().azureDefenderStatusLastUpdated());
        Assertions.assertEquals(DefenderStatus.UNPROTECTED, model.properties().azureDefenderStatus());
    }

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