// 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.fluent.models.EndpointHealthDataInner;
import com.azure.resourcemanager.iothub.models.EndpointHealthDataListResult;
import com.azure.resourcemanager.iothub.models.EndpointHealthStatus;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class EndpointHealthDataListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        EndpointHealthDataListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"endpointId\":\"zvahapjy\",\"healthStatus\":\"dead\",\"lastKnownError\":\"gqzcjr\",\"lastKnownErrorTime\":\"Sat,"
                        + " 03 Apr 2021 19:52:37 GMT\",\"lastSuccessfulSendAttemptTime\":\"Sat, 05 Jun 2021 18:59:27"
                        + " GMT\",\"lastSendAttemptTime\":\"Sat, 04 Sep 2021 18:51:43"
                        + " GMT\"},{\"endpointId\":\"lxkvu\",\"healthStatus\":\"degraded\",\"lastKnownError\":\"ovawjvzunlu\",\"lastKnownErrorTime\":\"Thu,"
                        + " 05 Aug 2021 22:08:57 GMT\",\"lastSuccessfulSendAttemptTime\":\"Thu, 21 Jan 2021 11:08:17"
                        + " GMT\",\"lastSendAttemptTime\":\"Thu, 11 Mar 2021 05:06:45"
                        + " GMT\"},{\"endpointId\":\"i\",\"healthStatus\":\"healthy\",\"lastKnownError\":\"pjzu\",\"lastKnownErrorTime\":\"Tue,"
                        + " 12 Oct 2021 12:24:32 GMT\",\"lastSuccessfulSendAttemptTime\":\"Mon, 21 Jun 2021 03:54:01"
                        + " GMT\",\"lastSendAttemptTime\":\"Wed, 03 Nov 2021 21:00:46"
                        + " GMT\"},{\"endpointId\":\"skzbb\",\"healthStatus\":\"dead\",\"lastKnownError\":\"mv\",\"lastKnownErrorTime\":\"Wed,"
                        + " 24 Feb 2021 15:47:12 GMT\",\"lastSuccessfulSendAttemptTime\":\"Mon, 22 Mar 2021 15:40:44"
                        + " GMT\",\"lastSendAttemptTime\":\"Thu, 01 Jul 2021 08:04:50 GMT\"}],\"nextLink\":\"uh\"}")
                .toObject(EndpointHealthDataListResult.class);
        Assertions.assertEquals("zvahapjy", model.value().get(0).endpointId());
        Assertions.assertEquals(EndpointHealthStatus.DEAD, model.value().get(0).healthStatus());
        Assertions.assertEquals("gqzcjr", model.value().get(0).lastKnownError());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-04-03T19:52:37Z"), model.value().get(0).lastKnownErrorTime());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-06-05T18:59:27Z"), model.value().get(0).lastSuccessfulSendAttemptTime());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-09-04T18:51:43Z"), model.value().get(0).lastSendAttemptTime());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        EndpointHealthDataListResult model =
            new EndpointHealthDataListResult()
                .withValue(
                    Arrays
                        .asList(
                            new EndpointHealthDataInner()
                                .withEndpointId("zvahapjy")
                                .withHealthStatus(EndpointHealthStatus.DEAD)
                                .withLastKnownError("gqzcjr")
                                .withLastKnownErrorTime(OffsetDateTime.parse("2021-04-03T19:52:37Z"))
                                .withLastSuccessfulSendAttemptTime(OffsetDateTime.parse("2021-06-05T18:59:27Z"))
                                .withLastSendAttemptTime(OffsetDateTime.parse("2021-09-04T18:51:43Z")),
                            new EndpointHealthDataInner()
                                .withEndpointId("lxkvu")
                                .withHealthStatus(EndpointHealthStatus.DEGRADED)
                                .withLastKnownError("ovawjvzunlu")
                                .withLastKnownErrorTime(OffsetDateTime.parse("2021-08-05T22:08:57Z"))
                                .withLastSuccessfulSendAttemptTime(OffsetDateTime.parse("2021-01-21T11:08:17Z"))
                                .withLastSendAttemptTime(OffsetDateTime.parse("2021-03-11T05:06:45Z")),
                            new EndpointHealthDataInner()
                                .withEndpointId("i")
                                .withHealthStatus(EndpointHealthStatus.HEALTHY)
                                .withLastKnownError("pjzu")
                                .withLastKnownErrorTime(OffsetDateTime.parse("2021-10-12T12:24:32Z"))
                                .withLastSuccessfulSendAttemptTime(OffsetDateTime.parse("2021-06-21T03:54:01Z"))
                                .withLastSendAttemptTime(OffsetDateTime.parse("2021-11-03T21:00:46Z")),
                            new EndpointHealthDataInner()
                                .withEndpointId("skzbb")
                                .withHealthStatus(EndpointHealthStatus.DEAD)
                                .withLastKnownError("mv")
                                .withLastKnownErrorTime(OffsetDateTime.parse("2021-02-24T15:47:12Z"))
                                .withLastSuccessfulSendAttemptTime(OffsetDateTime.parse("2021-03-22T15:40:44Z"))
                                .withLastSendAttemptTime(OffsetDateTime.parse("2021-07-01T08:04:50Z"))));
        model = BinaryData.fromObject(model).toObject(EndpointHealthDataListResult.class);
        Assertions.assertEquals("zvahapjy", model.value().get(0).endpointId());
        Assertions.assertEquals(EndpointHealthStatus.DEAD, model.value().get(0).healthStatus());
        Assertions.assertEquals("gqzcjr", model.value().get(0).lastKnownError());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-04-03T19:52:37Z"), model.value().get(0).lastKnownErrorTime());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-06-05T18:59:27Z"), model.value().get(0).lastSuccessfulSendAttemptTime());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-09-04T18:51:43Z"), model.value().get(0).lastSendAttemptTime());
    }
}
