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

package com.azure.resourcemanager.machinelearning.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.machinelearning.fluent.models.JobBaseInner;
import com.azure.resourcemanager.machinelearning.models.IdentityConfiguration;
import com.azure.resourcemanager.machinelearning.models.JobBaseProperties;
import com.azure.resourcemanager.machinelearning.models.JobService;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class JobBaseInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        JobBaseInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"jobType\":\"JobBaseProperties\",\"componentId\":\"fvjlboxqvkjlmx\",\"computeId\":\"mdy\",\"displayName\":\"dwdigumb\",\"experimentName\":\"aauzzptjazysd\",\"identity\":{\"identityType\":\"IdentityConfiguration\"},\"isArchived\":false,\"services\":{\"y\":{\"endpoint\":\"aiqyuvvfo\",\"errorMessage\":\"p\",\"jobServiceType\":\"qyikvy\",\"port\":1053518025,\"properties\":{},\"status\":\"vluwmncsttij\"}},\"status\":\"NotResponding\",\"description\":\"ekrsgs\",\"properties\":{\"dgkynscliqhzvhxn\":\"huzqgn\",\"tppn\":\"omtkub\",\"frbbc\":\"dxzxhi\"},\"tags\":{\"ykvgtrdcnifmz\":\"agtltdhlfkqoj\"}},\"id\":\"dymbrny\",\"name\":\"u\",\"type\":\"m\"}")
                .toObject(JobBaseInner.class);
        Assertions.assertEquals("ekrsgs", model.properties().description());
        Assertions.assertEquals("huzqgn", model.properties().properties().get("dgkynscliqhzvhxn"));
        Assertions.assertEquals("agtltdhlfkqoj", model.properties().tags().get("ykvgtrdcnifmz"));
        Assertions.assertEquals("fvjlboxqvkjlmx", model.properties().componentId());
        Assertions.assertEquals("mdy", model.properties().computeId());
        Assertions.assertEquals("dwdigumb", model.properties().displayName());
        Assertions.assertEquals("aauzzptjazysd", model.properties().experimentName());
        Assertions.assertEquals(false, model.properties().isArchived());
        Assertions.assertEquals("aiqyuvvfo", model.properties().services().get("y").endpoint());
        Assertions.assertEquals("qyikvy", model.properties().services().get("y").jobServiceType());
        Assertions.assertEquals(1053518025, model.properties().services().get("y").port());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        JobBaseInner model =
            new JobBaseInner()
                .withProperties(
                    new JobBaseProperties()
                        .withDescription("ekrsgs")
                        .withProperties(mapOf("dgkynscliqhzvhxn", "huzqgn", "tppn", "omtkub", "frbbc", "dxzxhi"))
                        .withTags(mapOf("ykvgtrdcnifmz", "agtltdhlfkqoj"))
                        .withComponentId("fvjlboxqvkjlmx")
                        .withComputeId("mdy")
                        .withDisplayName("dwdigumb")
                        .withExperimentName("aauzzptjazysd")
                        .withIdentity(new IdentityConfiguration())
                        .withIsArchived(false)
                        .withServices(
                            mapOf(
                                "y",
                                new JobService()
                                    .withEndpoint("aiqyuvvfo")
                                    .withJobServiceType("qyikvy")
                                    .withPort(1053518025)
                                    .withProperties(mapOf()))));
        model = BinaryData.fromObject(model).toObject(JobBaseInner.class);
        Assertions.assertEquals("ekrsgs", model.properties().description());
        Assertions.assertEquals("huzqgn", model.properties().properties().get("dgkynscliqhzvhxn"));
        Assertions.assertEquals("agtltdhlfkqoj", model.properties().tags().get("ykvgtrdcnifmz"));
        Assertions.assertEquals("fvjlboxqvkjlmx", model.properties().componentId());
        Assertions.assertEquals("mdy", model.properties().computeId());
        Assertions.assertEquals("dwdigumb", model.properties().displayName());
        Assertions.assertEquals("aauzzptjazysd", model.properties().experimentName());
        Assertions.assertEquals(false, model.properties().isArchived());
        Assertions.assertEquals("aiqyuvvfo", model.properties().services().get("y").endpoint());
        Assertions.assertEquals("qyikvy", model.properties().services().get("y").jobServiceType());
        Assertions.assertEquals(1053518025, model.properties().services().get("y").port());
    }

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