// 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.IntegrationAccountAgreementInner;
import com.azure.resourcemanager.logic.models.AgreementType;
import com.azure.resourcemanager.logic.models.IntegrationAccountAgreementListResult;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class IntegrationAccountAgreementListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        IntegrationAccountAgreementListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"createdTime\":\"2021-06-25T10:48:25Z\",\"changedTime\":\"2021-07-03T21:34:08Z\",\"metadata\":\"datayftumrtwna\",\"agreementType\":\"NotSpecified\",\"hostPartner\":\"slbi\",\"guestPartner\":\"kojgcyzts\"},\"location\":\"mznbaeqphch\",\"tags\":{\"ykqgaifmvik\":\"nrpxehuw\"},\"id\":\"bydvkhbejdz\",\"name\":\"xcv\",\"type\":\"srhnjivo\"},{\"properties\":{\"createdTime\":\"2021-08-24T07:08:09Z\",\"changedTime\":\"2021-03-07T07:40:39Z\",\"metadata\":\"dataqfzgemjdftul\",\"agreementType\":\"AS2\",\"hostPartner\":\"tduceamt\",\"guestPartner\":\"czu\"},\"location\":\"m\",\"tags\":{\"sx\":\"cwwqiokn\"},\"id\":\"ojmsvpkjprvkwc\",\"name\":\"zqljyxgtczh\",\"type\":\"ydbsd\"},{\"properties\":{\"createdTime\":\"2021-07-18T11:40:45Z\",\"changedTime\":\"2021-10-15T01:25:58Z\",\"metadata\":\"dataaehvbbxuri\",\"agreementType\":\"X12\",\"hostPartner\":\"tfnhtbaxkgxywr\",\"guestPartner\":\"kpyklyhp\"},\"location\":\"uodpv\",\"tags\":{\"tvdxeclzedqb\":\"dlgzibthostgkt\",\"lhpl\":\"vh\",\"lkxt\":\"dqkdlwwqfbu\",\"fwsrtawcoezbrhu\":\"qjfsmlmbtxhw\"},\"id\":\"skh\",\"name\":\"dyg\",\"type\":\"ookk\"}],\"nextLink\":\"qjbvleorfmlu\"}")
                .toObject(IntegrationAccountAgreementListResult.class);
        Assertions.assertEquals("mznbaeqphch", model.value().get(0).location());
        Assertions.assertEquals("nrpxehuw", model.value().get(0).tags().get("ykqgaifmvik"));
        Assertions.assertEquals(AgreementType.NOT_SPECIFIED, model.value().get(0).agreementType());
        Assertions.assertEquals("slbi", model.value().get(0).hostPartner());
        Assertions.assertEquals("kojgcyzts", model.value().get(0).guestPartner());
        Assertions.assertEquals("qjbvleorfmlu", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IntegrationAccountAgreementListResult model =
            new IntegrationAccountAgreementListResult()
                .withValue(
                    Arrays
                        .asList(
                            new IntegrationAccountAgreementInner()
                                .withLocation("mznbaeqphch")
                                .withTags(mapOf("ykqgaifmvik", "nrpxehuw"))
                                .withMetadata("datayftumrtwna")
                                .withAgreementType(AgreementType.NOT_SPECIFIED)
                                .withHostPartner("slbi")
                                .withGuestPartner("kojgcyzts"),
                            new IntegrationAccountAgreementInner()
                                .withLocation("m")
                                .withTags(mapOf("sx", "cwwqiokn"))
                                .withMetadata("dataqfzgemjdftul")
                                .withAgreementType(AgreementType.AS2)
                                .withHostPartner("tduceamt")
                                .withGuestPartner("czu"),
                            new IntegrationAccountAgreementInner()
                                .withLocation("uodpv")
                                .withTags(
                                    mapOf(
                                        "tvdxeclzedqb",
                                        "dlgzibthostgkt",
                                        "lhpl",
                                        "vh",
                                        "lkxt",
                                        "dqkdlwwqfbu",
                                        "fwsrtawcoezbrhu",
                                        "qjfsmlmbtxhw"))
                                .withMetadata("dataaehvbbxuri")
                                .withAgreementType(AgreementType.X12)
                                .withHostPartner("tfnhtbaxkgxywr")
                                .withGuestPartner("kpyklyhp")))
                .withNextLink("qjbvleorfmlu");
        model = BinaryData.fromObject(model).toObject(IntegrationAccountAgreementListResult.class);
        Assertions.assertEquals("mznbaeqphch", model.value().get(0).location());
        Assertions.assertEquals("nrpxehuw", model.value().get(0).tags().get("ykqgaifmvik"));
        Assertions.assertEquals(AgreementType.NOT_SPECIFIED, model.value().get(0).agreementType());
        Assertions.assertEquals("slbi", model.value().get(0).hostPartner());
        Assertions.assertEquals("kojgcyzts", model.value().get(0).guestPartner());
        Assertions.assertEquals("qjbvleorfmlu", model.nextLink());
    }

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