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

package com.azure.resourcemanager.storagecache.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.storagecache.fluent.models.StorageTargetInner;
import com.azure.resourcemanager.storagecache.models.BlobNfsTarget;
import com.azure.resourcemanager.storagecache.models.ClfsTarget;
import com.azure.resourcemanager.storagecache.models.NamespaceJunction;
import com.azure.resourcemanager.storagecache.models.Nfs3Target;
import com.azure.resourcemanager.storagecache.models.OperationalStateType;
import com.azure.resourcemanager.storagecache.models.StorageTargetType;
import com.azure.resourcemanager.storagecache.models.UnknownTarget;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class StorageTargetInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        StorageTargetInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"junctions\":[{\"namespacePath\":\"hvoodsotbobzd\",\"targetPath\":\"cjwvn\",\"nfsExport\":\"ld\",\"nfsAccessPolicy\":\"gx\"},{\"namespacePath\":\"rslpmutwuoeg\",\"targetPath\":\"khjwn\",\"nfsExport\":\"qsluicp\",\"nfsAccessPolicy\":\"gk\"},{\"namespacePath\":\"lvmbmpaxmodfvuef\",\"targetPath\":\"sbpfvmwyhr\",\"nfsExport\":\"uyfta\",\"nfsAccessPolicy\":\"cpwi\"}],\"targetType\":\"unknown\",\"provisioningState\":\"Failed\",\"state\":\"Flushing\",\"nfs3\":{\"target\":\"bexkpzksmondj\",\"usageModel\":\"uxvypomgkopkwh\",\"verificationTimer\":10985850,\"writeBackTimer\":1397433575},\"clfs\":{\"target\":\"gxysmocmbqfqvm\"},\"unknown\":{\"attributes\":{\"rgly\":\"zapvhelx\"}},\"blobNfs\":{\"target\":\"dckcbc\",\"usageModel\":\"jrjxgciqibrhosx\",\"verificationTimer\":1655789286,\"writeBackTimer\":656063523},\"allocationPercentage\":218775906},\"location\":\"m\",\"id\":\"m\",\"name\":\"qyib\",\"type\":\"hwflu\"}")
                .toObject(StorageTargetInner.class);
        Assertions.assertEquals("hvoodsotbobzd", model.junctions().get(0).namespacePath());
        Assertions.assertEquals("cjwvn", model.junctions().get(0).targetPath());
        Assertions.assertEquals("ld", model.junctions().get(0).nfsExport());
        Assertions.assertEquals("gx", model.junctions().get(0).nfsAccessPolicy());
        Assertions.assertEquals(StorageTargetType.UNKNOWN, model.targetType());
        Assertions.assertEquals(OperationalStateType.FLUSHING, model.state());
        Assertions.assertEquals("bexkpzksmondj", model.nfs3().target());
        Assertions.assertEquals("uxvypomgkopkwh", model.nfs3().usageModel());
        Assertions.assertEquals(10985850, model.nfs3().verificationTimer());
        Assertions.assertEquals(1397433575, model.nfs3().writeBackTimer());
        Assertions.assertEquals("gxysmocmbqfqvm", model.clfs().target());
        Assertions.assertEquals("zapvhelx", model.unknown().attributes().get("rgly"));
        Assertions.assertEquals("dckcbc", model.blobNfs().target());
        Assertions.assertEquals("jrjxgciqibrhosx", model.blobNfs().usageModel());
        Assertions.assertEquals(1655789286, model.blobNfs().verificationTimer());
        Assertions.assertEquals(656063523, model.blobNfs().writeBackTimer());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        StorageTargetInner model =
            new StorageTargetInner()
                .withJunctions(
                    Arrays
                        .asList(
                            new NamespaceJunction()
                                .withNamespacePath("hvoodsotbobzd")
                                .withTargetPath("cjwvn")
                                .withNfsExport("ld")
                                .withNfsAccessPolicy("gx"),
                            new NamespaceJunction()
                                .withNamespacePath("rslpmutwuoeg")
                                .withTargetPath("khjwn")
                                .withNfsExport("qsluicp")
                                .withNfsAccessPolicy("gk"),
                            new NamespaceJunction()
                                .withNamespacePath("lvmbmpaxmodfvuef")
                                .withTargetPath("sbpfvmwyhr")
                                .withNfsExport("uyfta")
                                .withNfsAccessPolicy("cpwi")))
                .withTargetType(StorageTargetType.UNKNOWN)
                .withState(OperationalStateType.FLUSHING)
                .withNfs3(
                    new Nfs3Target()
                        .withTarget("bexkpzksmondj")
                        .withUsageModel("uxvypomgkopkwh")
                        .withVerificationTimer(10985850)
                        .withWriteBackTimer(1397433575))
                .withClfs(new ClfsTarget().withTarget("gxysmocmbqfqvm"))
                .withUnknown(new UnknownTarget().withAttributes(mapOf("rgly", "zapvhelx")))
                .withBlobNfs(
                    new BlobNfsTarget()
                        .withTarget("dckcbc")
                        .withUsageModel("jrjxgciqibrhosx")
                        .withVerificationTimer(1655789286)
                        .withWriteBackTimer(656063523));
        model = BinaryData.fromObject(model).toObject(StorageTargetInner.class);
        Assertions.assertEquals("hvoodsotbobzd", model.junctions().get(0).namespacePath());
        Assertions.assertEquals("cjwvn", model.junctions().get(0).targetPath());
        Assertions.assertEquals("ld", model.junctions().get(0).nfsExport());
        Assertions.assertEquals("gx", model.junctions().get(0).nfsAccessPolicy());
        Assertions.assertEquals(StorageTargetType.UNKNOWN, model.targetType());
        Assertions.assertEquals(OperationalStateType.FLUSHING, model.state());
        Assertions.assertEquals("bexkpzksmondj", model.nfs3().target());
        Assertions.assertEquals("uxvypomgkopkwh", model.nfs3().usageModel());
        Assertions.assertEquals(10985850, model.nfs3().verificationTimer());
        Assertions.assertEquals(1397433575, model.nfs3().writeBackTimer());
        Assertions.assertEquals("gxysmocmbqfqvm", model.clfs().target());
        Assertions.assertEquals("zapvhelx", model.unknown().attributes().get("rgly"));
        Assertions.assertEquals("dckcbc", model.blobNfs().target());
        Assertions.assertEquals("jrjxgciqibrhosx", model.blobNfs().usageModel());
        Assertions.assertEquals(1655789286, model.blobNfs().verificationTimer());
        Assertions.assertEquals(656063523, model.blobNfs().writeBackTimer());
    }

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