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

package com.azure.resourcemanager.appcomplianceautomation.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.appcomplianceautomation.models.ReportProperties;
import com.azure.resourcemanager.appcomplianceautomation.models.ReportResourcePatch;
import com.azure.resourcemanager.appcomplianceautomation.models.ResourceMetadata;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class ReportResourcePatchTests {
    @Test
    public void testDeserialize() {
        ReportResourcePatch model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"id\":\"qktapspwgcuert\",\"status\":\"Failed\",\"tenantId\":\"o\",\"reportName\":\"qw\",\"offerGuid\":\"mdgbbjfdd\",\"timeZone\":\"mbmbexppbh\",\"triggerTime\":\"2021-05-23T22:50:57Z\",\"nextTriggerTime\":\"2021-10-16T18:25:20Z\",\"lastTriggerTime\":\"2021-06-19T01:51:06Z\",\"subscriptions\":[\"fpsalgbqu\"],\"resources\":[{\"resourceId\":\"gjyjgzjaoyfhrtxi\",\"resourceType\":\"erkujys\",\"resourceKind\":\"eju\",\"resourceName\":\"qawrlyxwj\",\"tags\":{}},{\"resourceId\":\"prbnwbxgjvtbv\",\"resourceType\":\"sszdnru\",\"resourceKind\":\"guhmuouqfpr\",\"resourceName\":\"wbnguitnwui\",\"tags\":{}}],\"complianceStatus\":{},\"provisioningState\":\"Failed\"}}")
                .toObject(ReportResourcePatch.class);
        Assertions.assertEquals("mdgbbjfdd", model.properties().offerGuid());
        Assertions.assertEquals("mbmbexppbh", model.properties().timeZone());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-23T22:50:57Z"), model.properties().triggerTime());
        Assertions.assertEquals("gjyjgzjaoyfhrtxi", model.properties().resources().get(0).resourceId());
        Assertions.assertEquals("erkujys", model.properties().resources().get(0).resourceType());
        Assertions.assertEquals("eju", model.properties().resources().get(0).resourceKind());
        Assertions.assertEquals("qawrlyxwj", model.properties().resources().get(0).resourceName());
    }

    @Test
    public void testSerialize() {
        ReportResourcePatch model =
            new ReportResourcePatch()
                .withProperties(
                    new ReportProperties()
                        .withOfferGuid("mdgbbjfdd")
                        .withTimeZone("mbmbexppbh")
                        .withTriggerTime(OffsetDateTime.parse("2021-05-23T22:50:57Z"))
                        .withResources(
                            Arrays
                                .asList(
                                    new ResourceMetadata()
                                        .withResourceId("gjyjgzjaoyfhrtxi")
                                        .withResourceType("erkujys")
                                        .withResourceKind("eju")
                                        .withResourceName("qawrlyxwj")
                                        .withTags(mapOf()),
                                    new ResourceMetadata()
                                        .withResourceId("prbnwbxgjvtbv")
                                        .withResourceType("sszdnru")
                                        .withResourceKind("guhmuouqfpr")
                                        .withResourceName("wbnguitnwui")
                                        .withTags(mapOf()))));
        model = BinaryData.fromObject(model).toObject(ReportResourcePatch.class);
        Assertions.assertEquals("mdgbbjfdd", model.properties().offerGuid());
        Assertions.assertEquals("mbmbexppbh", model.properties().timeZone());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-23T22:50:57Z"), model.properties().triggerTime());
        Assertions.assertEquals("gjyjgzjaoyfhrtxi", model.properties().resources().get(0).resourceId());
        Assertions.assertEquals("erkujys", model.properties().resources().get(0).resourceType());
        Assertions.assertEquals("eju", model.properties().resources().get(0).resourceKind());
        Assertions.assertEquals("qawrlyxwj", model.properties().resources().get(0).resourceName());
    }

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