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

package com.azure.resourcemanager.changeanalysis.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.changeanalysis.fluent.models.ChangeInner;
import com.azure.resourcemanager.changeanalysis.models.ChangeList;
import com.azure.resourcemanager.changeanalysis.models.ChangeProperties;
import com.azure.resourcemanager.changeanalysis.models.ChangeType;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class ChangeListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ChangeList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"resourceId\":\"ryrtihfxtijbpzv\",\"timeStamp\":\"2021-10-14T13:51:33Z\",\"initiatedByList\":[],\"changeType\":\"Update\",\"propertyChanges\":[]},\"id\":\"glzufc\",\"name\":\"zk\",\"type\":\"hdbihan\"},{\"properties\":{\"resourceId\":\"fcbjysagithxqha\",\"timeStamp\":\"2021-01-28T13:36:26Z\",\"initiatedByList\":[],\"changeType\":\"Update\",\"propertyChanges\":[]},\"id\":\"wczbys\",\"name\":\"npqxuh\",\"type\":\"vyq\"},{\"properties\":{\"resourceId\":\"b\",\"timeStamp\":\"2021-06-19T13:57:47Z\",\"initiatedByList\":[],\"changeType\":\"Remove\",\"propertyChanges\":[]},\"id\":\"umjgrtfwvuk\",\"name\":\"gaudcc\",\"type\":\"nhsjcnyej\"}],\"nextLink\":\"ryhtnapczwlokjy\"}")
                .toObject(ChangeList.class);
        Assertions.assertEquals("ryrtihfxtijbpzv", model.value().get(0).properties().resourceId());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-10-14T13:51:33Z"), model.value().get(0).properties().timestamp());
        Assertions.assertEquals(ChangeType.UPDATE, model.value().get(0).properties().changeType());
        Assertions.assertEquals("ryhtnapczwlokjy", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ChangeList model =
            new ChangeList()
                .withValue(
                    Arrays
                        .asList(
                            new ChangeInner()
                                .withProperties(
                                    new ChangeProperties()
                                        .withResourceId("ryrtihfxtijbpzv")
                                        .withTimestamp(OffsetDateTime.parse("2021-10-14T13:51:33Z"))
                                        .withInitiatedByList(Arrays.asList())
                                        .withChangeType(ChangeType.UPDATE)
                                        .withPropertyChanges(Arrays.asList())),
                            new ChangeInner()
                                .withProperties(
                                    new ChangeProperties()
                                        .withResourceId("fcbjysagithxqha")
                                        .withTimestamp(OffsetDateTime.parse("2021-01-28T13:36:26Z"))
                                        .withInitiatedByList(Arrays.asList())
                                        .withChangeType(ChangeType.UPDATE)
                                        .withPropertyChanges(Arrays.asList())),
                            new ChangeInner()
                                .withProperties(
                                    new ChangeProperties()
                                        .withResourceId("b")
                                        .withTimestamp(OffsetDateTime.parse("2021-06-19T13:57:47Z"))
                                        .withInitiatedByList(Arrays.asList())
                                        .withChangeType(ChangeType.REMOVE)
                                        .withPropertyChanges(Arrays.asList()))))
                .withNextLink("ryhtnapczwlokjy");
        model = BinaryData.fromObject(model).toObject(ChangeList.class);
        Assertions.assertEquals("ryrtihfxtijbpzv", model.value().get(0).properties().resourceId());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-10-14T13:51:33Z"), model.value().get(0).properties().timestamp());
        Assertions.assertEquals(ChangeType.UPDATE, model.value().get(0).properties().changeType());
        Assertions.assertEquals("ryhtnapczwlokjy", model.nextLink());
    }
}
