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

package com.azure.resourcemanager.recoveryservicesbackup.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.recoveryservicesbackup.fluent.models.JobResourceInner;
import com.azure.resourcemanager.recoveryservicesbackup.models.BackupManagementType;
import com.azure.resourcemanager.recoveryservicesbackup.models.Job;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class JobResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        JobResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"jobType\":\"Job\",\"entityFriendlyName\":\"anuzbpzkafkuw\",\"backupManagementType\":\"AzureIaasVM\",\"operation\":\"wbme\",\"status\":\"seyvj\",\"startTime\":\"2021-09-13T12:12:28Z\",\"endTime\":\"2021-06-01T12:34:05Z\",\"activityId\":\"hspkdeemao\"},\"eTag\":\"xagkvtmelmqkrh\",\"location\":\"hvljuahaquh\",\"tags\":{\"aex\":\"mdua\",\"vxpvgomz\":\"pvfadmwsrcr\"},\"id\":\"fmisg\",\"name\":\"bnbbeldawkz\",\"type\":\"ali\"}")
                .toObject(JobResourceInner.class);
        Assertions.assertEquals("hvljuahaquh", model.location());
        Assertions.assertEquals("mdua", model.tags().get("aex"));
        Assertions.assertEquals("anuzbpzkafkuw", model.properties().entityFriendlyName());
        Assertions.assertEquals(BackupManagementType.AZURE_IAAS_VM, model.properties().backupManagementType());
        Assertions.assertEquals("wbme", model.properties().operation());
        Assertions.assertEquals("seyvj", model.properties().status());
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-13T12:12:28Z"), model.properties().startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-01T12:34:05Z"), model.properties().endTime());
        Assertions.assertEquals("hspkdeemao", model.properties().activityId());
        Assertions.assertEquals("xagkvtmelmqkrh", model.etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        JobResourceInner model =
            new JobResourceInner()
                .withLocation("hvljuahaquh")
                .withTags(mapOf("aex", "mdua", "vxpvgomz", "pvfadmwsrcr"))
                .withProperties(
                    new Job()
                        .withEntityFriendlyName("anuzbpzkafkuw")
                        .withBackupManagementType(BackupManagementType.AZURE_IAAS_VM)
                        .withOperation("wbme")
                        .withStatus("seyvj")
                        .withStartTime(OffsetDateTime.parse("2021-09-13T12:12:28Z"))
                        .withEndTime(OffsetDateTime.parse("2021-06-01T12:34:05Z"))
                        .withActivityId("hspkdeemao"))
                .withEtag("xagkvtmelmqkrh");
        model = BinaryData.fromObject(model).toObject(JobResourceInner.class);
        Assertions.assertEquals("hvljuahaquh", model.location());
        Assertions.assertEquals("mdua", model.tags().get("aex"));
        Assertions.assertEquals("anuzbpzkafkuw", model.properties().entityFriendlyName());
        Assertions.assertEquals(BackupManagementType.AZURE_IAAS_VM, model.properties().backupManagementType());
        Assertions.assertEquals("wbme", model.properties().operation());
        Assertions.assertEquals("seyvj", model.properties().status());
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-13T12:12:28Z"), model.properties().startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-06-01T12:34:05Z"), model.properties().endTime());
        Assertions.assertEquals("hspkdeemao", model.properties().activityId());
        Assertions.assertEquals("xagkvtmelmqkrh", model.etag());
    }

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