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

package com.azure.resourcemanager.devtestlabs.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.devtestlabs.fluent.models.CustomImageInner;
import com.azure.resourcemanager.devtestlabs.models.CustomImageOsType;
import com.azure.resourcemanager.devtestlabs.models.CustomImagePropertiesCustom;
import com.azure.resourcemanager.devtestlabs.models.CustomImagePropertiesFromPlan;
import com.azure.resourcemanager.devtestlabs.models.CustomImagePropertiesFromVm;
import com.azure.resourcemanager.devtestlabs.models.DataDiskStorageTypeInfo;
import com.azure.resourcemanager.devtestlabs.models.StorageType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class CustomImageInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        CustomImageInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"vm\":{\"sourceVmId\":\"tllxdyhgsyocogj\"},\"vhd\":{\"imageName\":\"nnhad\",\"sysPrep\":true,\"osType\":\"None\"},\"description\":\"vcikhnvpamqgx\",\"author\":\"u\",\"creationDate\":\"2021-03-05T06:14:11Z\",\"managedImageId\":\"ywggx\",\"managedSnapshotId\":\"lla\",\"dataDiskStorageInfo\":[{\"lun\":\"wuipiccjzkzivg\",\"storageType\":\"Standard\"},{\"lun\":\"ayrhyrnx\",\"storageType\":\"Premium\"}],\"customImagePlan\":{\"id\":\"dndrdvstkwqqtche\",\"publisher\":\"mfmtdaaygdvw\",\"offer\":\"piohgwxrtfu\"},\"isPlanAuthorized\":true,\"provisioningState\":\"xg\",\"uniqueIdentifier\":\"agvrvmnpkuk\"},\"location\":\"himdbl\",\"tags\":{\"mszkkfo\":\"imfnjhfjx\"},\"id\":\"rey\",\"name\":\"kzikfjawneaivxwc\",\"type\":\"elpcirelsfeaenwa\"}")
                .toObject(CustomImageInner.class);
        Assertions.assertEquals("himdbl", model.location());
        Assertions.assertEquals("imfnjhfjx", model.tags().get("mszkkfo"));
        Assertions.assertEquals("tllxdyhgsyocogj", model.vm().sourceVmId());
        Assertions.assertEquals("nnhad", model.vhd().imageName());
        Assertions.assertEquals(true, model.vhd().sysPrep());
        Assertions.assertEquals(CustomImageOsType.NONE, model.vhd().osType());
        Assertions.assertEquals("vcikhnvpamqgx", model.description());
        Assertions.assertEquals("u", model.author());
        Assertions.assertEquals("ywggx", model.managedImageId());
        Assertions.assertEquals("lla", model.managedSnapshotId());
        Assertions.assertEquals("wuipiccjzkzivg", model.dataDiskStorageInfo().get(0).lun());
        Assertions.assertEquals(StorageType.STANDARD, model.dataDiskStorageInfo().get(0).storageType());
        Assertions.assertEquals("dndrdvstkwqqtche", model.customImagePlan().id());
        Assertions.assertEquals("mfmtdaaygdvw", model.customImagePlan().publisher());
        Assertions.assertEquals("piohgwxrtfu", model.customImagePlan().offer());
        Assertions.assertEquals(true, model.isPlanAuthorized());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        CustomImageInner model =
            new CustomImageInner()
                .withLocation("himdbl")
                .withTags(mapOf("mszkkfo", "imfnjhfjx"))
                .withVm(new CustomImagePropertiesFromVm().withSourceVmId("tllxdyhgsyocogj"))
                .withVhd(
                    new CustomImagePropertiesCustom()
                        .withImageName("nnhad")
                        .withSysPrep(true)
                        .withOsType(CustomImageOsType.NONE))
                .withDescription("vcikhnvpamqgx")
                .withAuthor("u")
                .withManagedImageId("ywggx")
                .withManagedSnapshotId("lla")
                .withDataDiskStorageInfo(
                    Arrays
                        .asList(
                            new DataDiskStorageTypeInfo()
                                .withLun("wuipiccjzkzivg")
                                .withStorageType(StorageType.STANDARD),
                            new DataDiskStorageTypeInfo().withLun("ayrhyrnx").withStorageType(StorageType.PREMIUM)))
                .withCustomImagePlan(
                    new CustomImagePropertiesFromPlan()
                        .withId("dndrdvstkwqqtche")
                        .withPublisher("mfmtdaaygdvw")
                        .withOffer("piohgwxrtfu"))
                .withIsPlanAuthorized(true);
        model = BinaryData.fromObject(model).toObject(CustomImageInner.class);
        Assertions.assertEquals("himdbl", model.location());
        Assertions.assertEquals("imfnjhfjx", model.tags().get("mszkkfo"));
        Assertions.assertEquals("tllxdyhgsyocogj", model.vm().sourceVmId());
        Assertions.assertEquals("nnhad", model.vhd().imageName());
        Assertions.assertEquals(true, model.vhd().sysPrep());
        Assertions.assertEquals(CustomImageOsType.NONE, model.vhd().osType());
        Assertions.assertEquals("vcikhnvpamqgx", model.description());
        Assertions.assertEquals("u", model.author());
        Assertions.assertEquals("ywggx", model.managedImageId());
        Assertions.assertEquals("lla", model.managedSnapshotId());
        Assertions.assertEquals("wuipiccjzkzivg", model.dataDiskStorageInfo().get(0).lun());
        Assertions.assertEquals(StorageType.STANDARD, model.dataDiskStorageInfo().get(0).storageType());
        Assertions.assertEquals("dndrdvstkwqqtche", model.customImagePlan().id());
        Assertions.assertEquals("mfmtdaaygdvw", model.customImagePlan().publisher());
        Assertions.assertEquals("piohgwxrtfu", model.customImagePlan().offer());
        Assertions.assertEquals(true, model.isPlanAuthorized());
    }

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