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

package com.azure.resourcemanager.databox.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.databox.fluent.models.JobResourceInner;
import com.azure.resourcemanager.databox.models.JobDeliveryType;
import com.azure.resourcemanager.databox.models.JobResourceList;
import com.azure.resourcemanager.databox.models.ResourceIdentity;
import com.azure.resourcemanager.databox.models.Sku;
import com.azure.resourcemanager.databox.models.SkuName;
import com.azure.resourcemanager.databox.models.TransferType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class JobResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        JobResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"transferType\":\"ExportFromAzure\",\"isCancellable\":false,\"isDeletable\":true,\"isShippingAddressEditable\":false,\"reverseShippingDetailsUpdate\":\"NotSupported\",\"reverseTransportPreferenceUpdate\":\"Enabled\",\"isPrepareToShipEnabled\":false,\"status\":\"DataCopy\",\"startTime\":\"2021-09-02T05:03:22Z\",\"cancellationReason\":\"napczwlokjy\",\"deliveryType\":\"Scheduled\",\"isCancellableWithoutFee\":false},\"name\":\"f\",\"id\":\"qtrgqjbpfzfsinzg\",\"type\":\"jrwzox\",\"sku\":{\"name\":\"DataBoxCustomerDisk\",\"displayName\":\"jsprozvcpute\",\"family\":\"vwmf\"},\"identity\":{\"type\":\"scmdvpjhulsuu\",\"principalId\":\"kjozkrwfnd\",\"tenantId\":\"djpslw\",\"userAssignedIdentities\":{}},\"location\":\"dpvwryoqpsoaccta\",\"tags\":{\"dfdosygexp\":\"ljlahbcryf\",\"dphlxaolt\":\"ojakhmsbzjhcrze\"}},{\"properties\":{\"transferType\":\"ImportToAzure\",\"isCancellable\":true,\"isDeletable\":true,\"isShippingAddressEditable\":true,\"reverseShippingDetailsUpdate\":\"Disabled\",\"reverseTransportPreferenceUpdate\":\"NotSupported\",\"isPrepareToShipEnabled\":true,\"status\":\"Cancelled\",\"startTime\":\"2021-03-02T22:56:24Z\",\"cancellationReason\":\"kjlxofpdvhpf\",\"deliveryType\":\"NonScheduled\",\"isCancellableWithoutFee\":true},\"name\":\"lssai\",\"id\":\"wtnhxbnjbiksqr\",\"type\":\"qpjwnzlljfm\",\"sku\":{\"name\":\"DataBoxDisk\",\"displayName\":\"o\",\"family\":\"si\"},\"identity\":{\"type\":\"v\",\"principalId\":\"iqihn\",\"tenantId\":\"ngbwjz\",\"userAssignedIdentities\":{}},\"location\":\"fygxgispemvtzfk\",\"tags\":{\"aeqjhqjbasvms\":\"bljofxqeof\",\"gsntnbybkzgcwr\":\"jqul\",\"skcqvkocrcjd\":\"clxxwrljdo\"}},{\"properties\":{\"transferType\":\"ImportToAzure\",\"isCancellable\":true,\"isDeletable\":false,\"isShippingAddressEditable\":false,\"reverseShippingDetailsUpdate\":\"Disabled\",\"reverseTransportPreferenceUpdate\":\"Disabled\",\"isPrepareToShipEnabled\":false,\"status\":\"AwaitingShipmentDetails\",\"startTime\":\"2021-06-19T04:22:24Z\",\"cancellationReason\":\"c\",\"deliveryType\":\"NonScheduled\",\"isCancellableWithoutFee\":false},\"name\":\"i\",\"id\":\"qgoulznd\",\"type\":\"wyqkgfgibm\",\"sku\":{\"name\":\"DataBoxCustomerDisk\",\"displayName\":\"utjeltmrldhugj\",\"family\":\"datqxhocdgeabl\"},\"identity\":{\"type\":\"uticndvkaozwyif\",\"principalId\":\"hxh\",\"tenantId\":\"okftyxolniwpwcuk\",\"userAssignedIdentities\":{}},\"location\":\"kgiawxklryplwck\",\"tags\":{\"koty\":\"yypnddhsgcbacphe\"}}],\"nextLink\":\"gakeqsr\"}")
                .toObject(JobResourceList.class);
        Assertions.assertEquals("dpvwryoqpsoaccta", model.value().get(0).location());
        Assertions.assertEquals("ljlahbcryf", model.value().get(0).tags().get("dfdosygexp"));
        Assertions.assertEquals(SkuName.DATA_BOX_CUSTOMER_DISK, model.value().get(0).sku().name());
        Assertions.assertEquals("jsprozvcpute", model.value().get(0).sku().displayName());
        Assertions.assertEquals("vwmf", model.value().get(0).sku().family());
        Assertions.assertEquals("scmdvpjhulsuu", model.value().get(0).identity().type());
        Assertions.assertEquals(TransferType.EXPORT_FROM_AZURE, model.value().get(0).transferType());
        Assertions.assertEquals(JobDeliveryType.SCHEDULED, model.value().get(0).deliveryType());
        Assertions.assertEquals("gakeqsr", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        JobResourceList model =
            new JobResourceList()
                .withValue(
                    Arrays
                        .asList(
                            new JobResourceInner()
                                .withLocation("dpvwryoqpsoaccta")
                                .withTags(mapOf("dfdosygexp", "ljlahbcryf", "dphlxaolt", "ojakhmsbzjhcrze"))
                                .withSku(
                                    new Sku()
                                        .withName(SkuName.DATA_BOX_CUSTOMER_DISK)
                                        .withDisplayName("jsprozvcpute")
                                        .withFamily("vwmf"))
                                .withIdentity(
                                    new ResourceIdentity()
                                        .withType("scmdvpjhulsuu")
                                        .withUserAssignedIdentities(mapOf()))
                                .withTransferType(TransferType.EXPORT_FROM_AZURE)
                                .withDeliveryType(JobDeliveryType.SCHEDULED),
                            new JobResourceInner()
                                .withLocation("fygxgispemvtzfk")
                                .withTags(
                                    mapOf(
                                        "aeqjhqjbasvms",
                                        "bljofxqeof",
                                        "gsntnbybkzgcwr",
                                        "jqul",
                                        "skcqvkocrcjd",
                                        "clxxwrljdo"))
                                .withSku(
                                    new Sku().withName(SkuName.DATA_BOX_DISK).withDisplayName("o").withFamily("si"))
                                .withIdentity(new ResourceIdentity().withType("v").withUserAssignedIdentities(mapOf()))
                                .withTransferType(TransferType.IMPORT_TO_AZURE)
                                .withDeliveryType(JobDeliveryType.NON_SCHEDULED),
                            new JobResourceInner()
                                .withLocation("kgiawxklryplwck")
                                .withTags(mapOf("koty", "yypnddhsgcbacphe"))
                                .withSku(
                                    new Sku()
                                        .withName(SkuName.DATA_BOX_CUSTOMER_DISK)
                                        .withDisplayName("utjeltmrldhugj")
                                        .withFamily("datqxhocdgeabl"))
                                .withIdentity(
                                    new ResourceIdentity()
                                        .withType("uticndvkaozwyif")
                                        .withUserAssignedIdentities(mapOf()))
                                .withTransferType(TransferType.IMPORT_TO_AZURE)
                                .withDeliveryType(JobDeliveryType.NON_SCHEDULED)))
                .withNextLink("gakeqsr");
        model = BinaryData.fromObject(model).toObject(JobResourceList.class);
        Assertions.assertEquals("dpvwryoqpsoaccta", model.value().get(0).location());
        Assertions.assertEquals("ljlahbcryf", model.value().get(0).tags().get("dfdosygexp"));
        Assertions.assertEquals(SkuName.DATA_BOX_CUSTOMER_DISK, model.value().get(0).sku().name());
        Assertions.assertEquals("jsprozvcpute", model.value().get(0).sku().displayName());
        Assertions.assertEquals("vwmf", model.value().get(0).sku().family());
        Assertions.assertEquals("scmdvpjhulsuu", model.value().get(0).identity().type());
        Assertions.assertEquals(TransferType.EXPORT_FROM_AZURE, model.value().get(0).transferType());
        Assertions.assertEquals(JobDeliveryType.SCHEDULED, model.value().get(0).deliveryType());
        Assertions.assertEquals("gakeqsr", model.nextLink());
    }

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