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

package com.azure.resourcemanager.imagebuilder.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.imagebuilder.models.DistributeVersioner;
import com.azure.resourcemanager.imagebuilder.models.ImageTemplateSharedImageDistributor;
import com.azure.resourcemanager.imagebuilder.models.SharedImageStorageAccountType;
import com.azure.resourcemanager.imagebuilder.models.TargetRegion;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ImageTemplateSharedImageDistributorTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ImageTemplateSharedImageDistributor model =
            BinaryData
                .fromString(
                    "{\"type\":\"SharedImage\",\"galleryImageId\":\"byao\",\"replicationRegions\":[\"xc\"],\"excludeFromLatest\":false,\"storageAccountType\":\"Standard_LRS\",\"targetRegions\":[{\"name\":\"ocohslkevleg\",\"replicaCount\":1396926466,\"storageAccountType\":\"Standard_LRS\"},{\"name\":\"hfmvfaxkffe\",\"replicaCount\":517393984,\"storageAccountType\":\"Standard_LRS\"},{\"name\":\"vmezy\",\"replicaCount\":1090911341,\"storageAccountType\":\"Standard_LRS\"}],\"versioning\":{\"scheme\":\"DistributeVersioner\"},\"runOutputName\":\"sbbzo\",\"artifactTags\":{\"vjxxjnsp\":\"grxwbu\",\"vudwtiukbldng\":\"dptkoenkouk\",\"g\":\"pocipazyxoegu\",\"mrbpizcdrqj\":\"npiucgygevqznty\"}}")
                .toObject(ImageTemplateSharedImageDistributor.class);
        Assertions.assertEquals("sbbzo", model.runOutputName());
        Assertions.assertEquals("grxwbu", model.artifactTags().get("vjxxjnsp"));
        Assertions.assertEquals("byao", model.galleryImageId());
        Assertions.assertEquals("xc", model.replicationRegions().get(0));
        Assertions.assertEquals(false, model.excludeFromLatest());
        Assertions.assertEquals(SharedImageStorageAccountType.STANDARD_LRS, model.storageAccountType());
        Assertions.assertEquals("ocohslkevleg", model.targetRegions().get(0).name());
        Assertions.assertEquals(1396926466, model.targetRegions().get(0).replicaCount());
        Assertions
            .assertEquals(
                SharedImageStorageAccountType.STANDARD_LRS, model.targetRegions().get(0).storageAccountType());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ImageTemplateSharedImageDistributor model =
            new ImageTemplateSharedImageDistributor()
                .withRunOutputName("sbbzo")
                .withArtifactTags(
                    mapOf(
                        "vjxxjnsp",
                        "grxwbu",
                        "vudwtiukbldng",
                        "dptkoenkouk",
                        "g",
                        "pocipazyxoegu",
                        "mrbpizcdrqj",
                        "npiucgygevqznty"))
                .withGalleryImageId("byao")
                .withReplicationRegions(Arrays.asList("xc"))
                .withExcludeFromLatest(false)
                .withStorageAccountType(SharedImageStorageAccountType.STANDARD_LRS)
                .withTargetRegions(
                    Arrays
                        .asList(
                            new TargetRegion()
                                .withName("ocohslkevleg")
                                .withReplicaCount(1396926466)
                                .withStorageAccountType(SharedImageStorageAccountType.STANDARD_LRS),
                            new TargetRegion()
                                .withName("hfmvfaxkffe")
                                .withReplicaCount(517393984)
                                .withStorageAccountType(SharedImageStorageAccountType.STANDARD_LRS),
                            new TargetRegion()
                                .withName("vmezy")
                                .withReplicaCount(1090911341)
                                .withStorageAccountType(SharedImageStorageAccountType.STANDARD_LRS)))
                .withVersioning(new DistributeVersioner());
        model = BinaryData.fromObject(model).toObject(ImageTemplateSharedImageDistributor.class);
        Assertions.assertEquals("sbbzo", model.runOutputName());
        Assertions.assertEquals("grxwbu", model.artifactTags().get("vjxxjnsp"));
        Assertions.assertEquals("byao", model.galleryImageId());
        Assertions.assertEquals("xc", model.replicationRegions().get(0));
        Assertions.assertEquals(false, model.excludeFromLatest());
        Assertions.assertEquals(SharedImageStorageAccountType.STANDARD_LRS, model.storageAccountType());
        Assertions.assertEquals("ocohslkevleg", model.targetRegions().get(0).name());
        Assertions.assertEquals(1396926466, model.targetRegions().get(0).replicaCount());
        Assertions
            .assertEquals(
                SharedImageStorageAccountType.STANDARD_LRS, model.targetRegions().get(0).storageAccountType());
    }

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