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

package com.azure.resourcemanager.logic.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.logic.fluent.models.BatchConfigurationInner;
import com.azure.resourcemanager.logic.models.BatchConfigurationProperties;
import com.azure.resourcemanager.logic.models.BatchReleaseCriteria;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class BatchConfigurationInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        BatchConfigurationInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"batchGroupName\":\"kgymareqnajxqug\",\"releaseCriteria\":{\"messageCount\":432489630,\"batchSize\":1068546777},\"createdTime\":\"2021-05-25T15:55:45Z\",\"changedTime\":\"2020-12-26T14:38:09Z\",\"metadata\":\"datassofwqmzqa\"},\"location\":\"krmnjijpxacqqud\",\"tags\":{\"imrzrtuzqog\":\"yxbaaabjyvayf\",\"vfdnwnwmewzsyyce\":\"exn\",\"hzv\":\"zsoibjudpfrxtr\"},\"id\":\"ytdw\",\"name\":\"qbrqubpaxhexiili\",\"type\":\"pdtii\"}")
                .toObject(BatchConfigurationInner.class);
        Assertions.assertEquals("krmnjijpxacqqud", model.location());
        Assertions.assertEquals("yxbaaabjyvayf", model.tags().get("imrzrtuzqog"));
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-25T15:55:45Z"), model.properties().createdTime());
        Assertions.assertEquals(OffsetDateTime.parse("2020-12-26T14:38:09Z"), model.properties().changedTime());
        Assertions.assertEquals("kgymareqnajxqug", model.properties().batchGroupName());
        Assertions.assertEquals(432489630, model.properties().releaseCriteria().messageCount());
        Assertions.assertEquals(1068546777, model.properties().releaseCriteria().batchSize());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        BatchConfigurationInner model =
            new BatchConfigurationInner()
                .withLocation("krmnjijpxacqqud")
                .withTags(mapOf("imrzrtuzqog", "yxbaaabjyvayf", "vfdnwnwmewzsyyce", "exn", "hzv", "zsoibjudpfrxtr"))
                .withProperties(
                    new BatchConfigurationProperties()
                        .withCreatedTime(OffsetDateTime.parse("2021-05-25T15:55:45Z"))
                        .withChangedTime(OffsetDateTime.parse("2020-12-26T14:38:09Z"))
                        .withMetadata("datassofwqmzqa")
                        .withBatchGroupName("kgymareqnajxqug")
                        .withReleaseCriteria(
                            new BatchReleaseCriteria().withMessageCount(432489630).withBatchSize(1068546777)));
        model = BinaryData.fromObject(model).toObject(BatchConfigurationInner.class);
        Assertions.assertEquals("krmnjijpxacqqud", model.location());
        Assertions.assertEquals("yxbaaabjyvayf", model.tags().get("imrzrtuzqog"));
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-25T15:55:45Z"), model.properties().createdTime());
        Assertions.assertEquals(OffsetDateTime.parse("2020-12-26T14:38:09Z"), model.properties().changedTime());
        Assertions.assertEquals("kgymareqnajxqug", model.properties().batchGroupName());
        Assertions.assertEquals(432489630, model.properties().releaseCriteria().messageCount());
        Assertions.assertEquals(1068546777, model.properties().releaseCriteria().batchSize());
    }

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