// 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.StorageTargetProperties;
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 StorageTargetPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        StorageTargetProperties model =
            BinaryData
                .fromString(
                    "{\"junctions\":[{\"namespacePath\":\"mhrkwofyyvoqacp\",\"targetPath\":\"xpbtgiwbwo\",\"nfsExport\":\"washr\",\"nfsAccessPolicy\":\"tkcnqxwb\"},{\"namespacePath\":\"kulpiujwaasi\",\"targetPath\":\"i\",\"nfsExport\":\"byuqerpqlp\",\"nfsAccessPolicy\":\"cciuqgbdbutau\"},{\"namespacePath\":\"btkuwhh\",\"targetPath\":\"ykojoxafnndlpic\",\"nfsExport\":\"o\",\"nfsAccessPolicy\":\"kcdyhbpk\"},{\"namespacePath\":\"wdreqnovvqfovl\",\"targetPath\":\"ywsuwsy\",\"nfsExport\":\"ndsytgadg\",\"nfsAccessPolicy\":\"aeaeneqnzarrw\"}],\"targetType\":\"nfs3\",\"provisioningState\":\"Deleting\",\"state\":\"Busy\",\"nfs3\":{\"target\":\"kacewiipfp\",\"usageModel\":\"ji\",\"verificationTimer\":1113434704,\"writeBackTimer\":254804801},\"clfs\":{\"target\":\"hqkvpuvksgplsak\"},\"unknown\":{\"attributes\":{\"iyntorzihle\":\"synljphuopxodl\",\"yzrpzbchckqqzq\":\"sjswsrms\",\"ysuiizynkedya\":\"ox\"}},\"blobNfs\":{\"target\":\"yhqmibzyhwi\",\"usageModel\":\"mypyynpcdpu\",\"verificationTimer\":1107344942,\"writeBackTimer\":998287381},\"allocationPercentage\":83591449}")
                .toObject(StorageTargetProperties.class);
        Assertions.assertEquals("mhrkwofyyvoqacp", model.junctions().get(0).namespacePath());
        Assertions.assertEquals("xpbtgiwbwo", model.junctions().get(0).targetPath());
        Assertions.assertEquals("washr", model.junctions().get(0).nfsExport());
        Assertions.assertEquals("tkcnqxwb", model.junctions().get(0).nfsAccessPolicy());
        Assertions.assertEquals(StorageTargetType.NFS3, model.targetType());
        Assertions.assertEquals(OperationalStateType.BUSY, model.state());
        Assertions.assertEquals("kacewiipfp", model.nfs3().target());
        Assertions.assertEquals("ji", model.nfs3().usageModel());
        Assertions.assertEquals(1113434704, model.nfs3().verificationTimer());
        Assertions.assertEquals(254804801, model.nfs3().writeBackTimer());
        Assertions.assertEquals("hqkvpuvksgplsak", model.clfs().target());
        Assertions.assertEquals("synljphuopxodl", model.unknown().attributes().get("iyntorzihle"));
        Assertions.assertEquals("yhqmibzyhwi", model.blobNfs().target());
        Assertions.assertEquals("mypyynpcdpu", model.blobNfs().usageModel());
        Assertions.assertEquals(1107344942, model.blobNfs().verificationTimer());
        Assertions.assertEquals(998287381, model.blobNfs().writeBackTimer());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        StorageTargetProperties model =
            new StorageTargetProperties()
                .withJunctions(
                    Arrays
                        .asList(
                            new NamespaceJunction()
                                .withNamespacePath("mhrkwofyyvoqacp")
                                .withTargetPath("xpbtgiwbwo")
                                .withNfsExport("washr")
                                .withNfsAccessPolicy("tkcnqxwb"),
                            new NamespaceJunction()
                                .withNamespacePath("kulpiujwaasi")
                                .withTargetPath("i")
                                .withNfsExport("byuqerpqlp")
                                .withNfsAccessPolicy("cciuqgbdbutau"),
                            new NamespaceJunction()
                                .withNamespacePath("btkuwhh")
                                .withTargetPath("ykojoxafnndlpic")
                                .withNfsExport("o")
                                .withNfsAccessPolicy("kcdyhbpk"),
                            new NamespaceJunction()
                                .withNamespacePath("wdreqnovvqfovl")
                                .withTargetPath("ywsuwsy")
                                .withNfsExport("ndsytgadg")
                                .withNfsAccessPolicy("aeaeneqnzarrw")))
                .withTargetType(StorageTargetType.NFS3)
                .withState(OperationalStateType.BUSY)
                .withNfs3(
                    new Nfs3Target()
                        .withTarget("kacewiipfp")
                        .withUsageModel("ji")
                        .withVerificationTimer(1113434704)
                        .withWriteBackTimer(254804801))
                .withClfs(new ClfsTarget().withTarget("hqkvpuvksgplsak"))
                .withUnknown(
                    new UnknownTarget()
                        .withAttributes(
                            mapOf(
                                "iyntorzihle", "synljphuopxodl", "yzrpzbchckqqzq", "sjswsrms", "ysuiizynkedya", "ox")))
                .withBlobNfs(
                    new BlobNfsTarget()
                        .withTarget("yhqmibzyhwi")
                        .withUsageModel("mypyynpcdpu")
                        .withVerificationTimer(1107344942)
                        .withWriteBackTimer(998287381));
        model = BinaryData.fromObject(model).toObject(StorageTargetProperties.class);
        Assertions.assertEquals("mhrkwofyyvoqacp", model.junctions().get(0).namespacePath());
        Assertions.assertEquals("xpbtgiwbwo", model.junctions().get(0).targetPath());
        Assertions.assertEquals("washr", model.junctions().get(0).nfsExport());
        Assertions.assertEquals("tkcnqxwb", model.junctions().get(0).nfsAccessPolicy());
        Assertions.assertEquals(StorageTargetType.NFS3, model.targetType());
        Assertions.assertEquals(OperationalStateType.BUSY, model.state());
        Assertions.assertEquals("kacewiipfp", model.nfs3().target());
        Assertions.assertEquals("ji", model.nfs3().usageModel());
        Assertions.assertEquals(1113434704, model.nfs3().verificationTimer());
        Assertions.assertEquals(254804801, model.nfs3().writeBackTimer());
        Assertions.assertEquals("hqkvpuvksgplsak", model.clfs().target());
        Assertions.assertEquals("synljphuopxodl", model.unknown().attributes().get("iyntorzihle"));
        Assertions.assertEquals("yhqmibzyhwi", model.blobNfs().target());
        Assertions.assertEquals("mypyynpcdpu", model.blobNfs().usageModel());
        Assertions.assertEquals(1107344942, model.blobNfs().verificationTimer());
        Assertions.assertEquals(998287381, 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;
    }
}
