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

package com.azure.resourcemanager.iothub.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.iothub.models.CloudToDeviceProperties;
import com.azure.resourcemanager.iothub.models.FeedbackProperties;
import java.time.Duration;
import org.junit.jupiter.api.Assertions;

public final class CloudToDevicePropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        CloudToDeviceProperties model =
            BinaryData
                .fromString(
                    "{\"maxDeliveryCount\":1121109847,\"defaultTtlAsIso8601\":\"PT84H30M6S\",\"feedback\":{\"lockDurationAsIso8601\":\"PT9H8M5S\",\"ttlAsIso8601\":\"PT205H49M51S\",\"maxDeliveryCount\":1139583555}}")
                .toObject(CloudToDeviceProperties.class);
        Assertions.assertEquals(1121109847, model.maxDeliveryCount());
        Assertions.assertEquals(Duration.parse("PT84H30M6S"), model.defaultTtlAsIso8601());
        Assertions.assertEquals(Duration.parse("PT9H8M5S"), model.feedback().lockDurationAsIso8601());
        Assertions.assertEquals(Duration.parse("PT205H49M51S"), model.feedback().ttlAsIso8601());
        Assertions.assertEquals(1139583555, model.feedback().maxDeliveryCount());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        CloudToDeviceProperties model =
            new CloudToDeviceProperties()
                .withMaxDeliveryCount(1121109847)
                .withDefaultTtlAsIso8601(Duration.parse("PT84H30M6S"))
                .withFeedback(
                    new FeedbackProperties()
                        .withLockDurationAsIso8601(Duration.parse("PT9H8M5S"))
                        .withTtlAsIso8601(Duration.parse("PT205H49M51S"))
                        .withMaxDeliveryCount(1139583555));
        model = BinaryData.fromObject(model).toObject(CloudToDeviceProperties.class);
        Assertions.assertEquals(1121109847, model.maxDeliveryCount());
        Assertions.assertEquals(Duration.parse("PT84H30M6S"), model.defaultTtlAsIso8601());
        Assertions.assertEquals(Duration.parse("PT9H8M5S"), model.feedback().lockDurationAsIso8601());
        Assertions.assertEquals(Duration.parse("PT205H49M51S"), model.feedback().ttlAsIso8601());
        Assertions.assertEquals(1139583555, model.feedback().maxDeliveryCount());
    }
}
