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

package com.azure.resourcemanager.managementgroups.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.managementgroups.fluent.models.ManagementGroupInner;
import com.azure.resourcemanager.managementgroups.models.ManagementGroupChildInfo;
import com.azure.resourcemanager.managementgroups.models.ManagementGroupChildType;
import com.azure.resourcemanager.managementgroups.models.ManagementGroupDetails;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class ManagementGroupInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ManagementGroupInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"tenantId\":\"ryuanzwuxzdxtay\",\"displayName\":\"hmwhfpmrqo\",\"details\":{\"version\":259988235,\"updatedTime\":\"2020-12-27T10:31:34Z\",\"updatedBy\":\"ryrtihfxtijbpzv\",\"path\":[],\"managementGroupAncestors\":[\"mglzufcy\",\"kohdbiha\",\"ufhfcbjysa\"],\"managementGroupAncestorsChain\":[]},\"children\":[{\"type\":\"Microsoft.Management/managementGroups\",\"id\":\"bifpikxwczb\",\"name\":\"cnpqxuhivyqniwby\",\"displayName\":\"k\",\"children\":[]},{\"type\":\"/subscriptions\",\"id\":\"jgrtfwvukxga\",\"name\":\"ccsnhsjc\",\"displayName\":\"ejhkry\",\"children\":[]}]},\"id\":\"napczwlokjy\",\"name\":\"mkkvnip\",\"type\":\"oxzjnchgejspod\"}")
                .toObject(ManagementGroupInner.class);
        Assertions.assertEquals("ryuanzwuxzdxtay", model.tenantId());
        Assertions.assertEquals("hmwhfpmrqo", model.displayName());
        Assertions.assertEquals(259988235, model.details().version());
        Assertions.assertEquals(OffsetDateTime.parse("2020-12-27T10:31:34Z"), model.details().updatedTime());
        Assertions.assertEquals("ryrtihfxtijbpzv", model.details().updatedBy());
        Assertions.assertEquals("mglzufcy", model.details().managementGroupAncestors().get(0));
        Assertions
            .assertEquals(
                ManagementGroupChildType.MICROSOFT_MANAGEMENT_MANAGEMENT_GROUPS, model.children().get(0).type());
        Assertions.assertEquals("bifpikxwczb", model.children().get(0).id());
        Assertions.assertEquals("cnpqxuhivyqniwby", model.children().get(0).name());
        Assertions.assertEquals("k", model.children().get(0).displayName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ManagementGroupInner model =
            new ManagementGroupInner()
                .withTenantId("ryuanzwuxzdxtay")
                .withDisplayName("hmwhfpmrqo")
                .withDetails(
                    new ManagementGroupDetails()
                        .withVersion(259988235)
                        .withUpdatedTime(OffsetDateTime.parse("2020-12-27T10:31:34Z"))
                        .withUpdatedBy("ryrtihfxtijbpzv")
                        .withPath(Arrays.asList())
                        .withManagementGroupAncestors(Arrays.asList("mglzufcy", "kohdbiha", "ufhfcbjysa"))
                        .withManagementGroupAncestorsChain(Arrays.asList()))
                .withChildren(
                    Arrays
                        .asList(
                            new ManagementGroupChildInfo()
                                .withType(ManagementGroupChildType.MICROSOFT_MANAGEMENT_MANAGEMENT_GROUPS)
                                .withId("bifpikxwczb")
                                .withName("cnpqxuhivyqniwby")
                                .withDisplayName("k")
                                .withChildren(Arrays.asList()),
                            new ManagementGroupChildInfo()
                                .withType(ManagementGroupChildType.SUBSCRIPTIONS)
                                .withId("jgrtfwvukxga")
                                .withName("ccsnhsjc")
                                .withDisplayName("ejhkry")
                                .withChildren(Arrays.asList())));
        model = BinaryData.fromObject(model).toObject(ManagementGroupInner.class);
        Assertions.assertEquals("ryuanzwuxzdxtay", model.tenantId());
        Assertions.assertEquals("hmwhfpmrqo", model.displayName());
        Assertions.assertEquals(259988235, model.details().version());
        Assertions.assertEquals(OffsetDateTime.parse("2020-12-27T10:31:34Z"), model.details().updatedTime());
        Assertions.assertEquals("ryrtihfxtijbpzv", model.details().updatedBy());
        Assertions.assertEquals("mglzufcy", model.details().managementGroupAncestors().get(0));
        Assertions
            .assertEquals(
                ManagementGroupChildType.MICROSOFT_MANAGEMENT_MANAGEMENT_GROUPS, model.children().get(0).type());
        Assertions.assertEquals("bifpikxwczb", model.children().get(0).id());
        Assertions.assertEquals("cnpqxuhivyqniwby", model.children().get(0).name());
        Assertions.assertEquals("k", model.children().get(0).displayName());
    }
}
