// 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.models.IdentityConfiguration;
import com.azure.resourcemanager.machinelearning.models.JobBaseProperties;
import com.azure.resourcemanager.machinelearning.models.JobScheduleAction;
import com.azure.resourcemanager.machinelearning.models.JobService;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class JobScheduleActionTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        JobScheduleAction model =
            BinaryData
                .fromString(
                    "{\"actionType\":\"CreateJob\",\"jobDefinition\":{\"jobType\":\"JobBaseProperties\",\"componentId\":\"xkydfbwlja\",\"computeId\":\"uerkjddvrg\",\"displayName\":\"egftcvb\",\"experimentName\":\"ftksd\",\"identity\":{\"identityType\":\"IdentityConfiguration\"},\"isArchived\":true,\"services\":{\"jgmn\":{\"endpoint\":\"gmwdh\",\"errorMessage\":\"buvczldbglzoutb\",\"jobServiceType\":\"qgz\",\"port\":1543957529,\"properties\":{},\"status\":\"lyzgsnor\"},\"rswhbuubpyro\":{\"endpoint\":\"otvmrxk\",\"errorMessage\":\"obvvjbhvh\",\"jobServiceType\":\"qayfl\",\"port\":307514340,\"properties\":{},\"status\":\"snuudtelvhyibdr\"},\"km\":{\"endpoint\":\"joxztfwfqchvczev\",\"errorMessage\":\"nctagfyvrtpqpem\",\"jobServiceType\":\"cgkrepdqhqy\",\"port\":1873371469,\"properties\":{},\"status\":\"mvxqab\"}},\"status\":\"NotStarted\",\"description\":\"inhgre\",\"properties\":{\"angp\":\"whlpuzjpceezn\",\"phmsexroq\":\"bfaxyxzlbc\",\"nfee\":\"ndktxfv\"},\"tags\":{\"bgnixxoww\":\"krie\",\"p\":\"kyfwnwpiwxeiicr\",\"dm\":\"pk\"}}}")
                .toObject(JobScheduleAction.class);
        Assertions.assertEquals("inhgre", model.jobDefinition().description());
        Assertions.assertEquals("whlpuzjpceezn", model.jobDefinition().properties().get("angp"));
        Assertions.assertEquals("krie", model.jobDefinition().tags().get("bgnixxoww"));
        Assertions.assertEquals("xkydfbwlja", model.jobDefinition().componentId());
        Assertions.assertEquals("uerkjddvrg", model.jobDefinition().computeId());
        Assertions.assertEquals("egftcvb", model.jobDefinition().displayName());
        Assertions.assertEquals("ftksd", model.jobDefinition().experimentName());
        Assertions.assertEquals(true, model.jobDefinition().isArchived());
        Assertions.assertEquals("gmwdh", model.jobDefinition().services().get("jgmn").endpoint());
        Assertions.assertEquals("qgz", model.jobDefinition().services().get("jgmn").jobServiceType());
        Assertions.assertEquals(1543957529, model.jobDefinition().services().get("jgmn").port());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        JobScheduleAction model =
            new JobScheduleAction()
                .withJobDefinition(
                    new JobBaseProperties()
                        .withDescription("inhgre")
                        .withProperties(mapOf("angp", "whlpuzjpceezn", "phmsexroq", "bfaxyxzlbc", "nfee", "ndktxfv"))
                        .withTags(mapOf("bgnixxoww", "krie", "p", "kyfwnwpiwxeiicr", "dm", "pk"))
                        .withComponentId("xkydfbwlja")
                        .withComputeId("uerkjddvrg")
                        .withDisplayName("egftcvb")
                        .withExperimentName("ftksd")
                        .withIdentity(new IdentityConfiguration())
                        .withIsArchived(true)
                        .withServices(
                            mapOf(
                                "jgmn",
                                new JobService()
                                    .withEndpoint("gmwdh")
                                    .withJobServiceType("qgz")
                                    .withPort(1543957529)
                                    .withProperties(mapOf()),
                                "rswhbuubpyro",
                                new JobService()
                                    .withEndpoint("otvmrxk")
                                    .withJobServiceType("qayfl")
                                    .withPort(307514340)
                                    .withProperties(mapOf()),
                                "km",
                                new JobService()
                                    .withEndpoint("joxztfwfqchvczev")
                                    .withJobServiceType("cgkrepdqhqy")
                                    .withPort(1873371469)
                                    .withProperties(mapOf()))));
        model = BinaryData.fromObject(model).toObject(JobScheduleAction.class);
        Assertions.assertEquals("inhgre", model.jobDefinition().description());
        Assertions.assertEquals("whlpuzjpceezn", model.jobDefinition().properties().get("angp"));
        Assertions.assertEquals("krie", model.jobDefinition().tags().get("bgnixxoww"));
        Assertions.assertEquals("xkydfbwlja", model.jobDefinition().componentId());
        Assertions.assertEquals("uerkjddvrg", model.jobDefinition().computeId());
        Assertions.assertEquals("egftcvb", model.jobDefinition().displayName());
        Assertions.assertEquals("ftksd", model.jobDefinition().experimentName());
        Assertions.assertEquals(true, model.jobDefinition().isArchived());
        Assertions.assertEquals("gmwdh", model.jobDefinition().services().get("jgmn").endpoint());
        Assertions.assertEquals("qgz", model.jobDefinition().services().get("jgmn").jobServiceType());
        Assertions.assertEquals(1543957529, model.jobDefinition().services().get("jgmn").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;
    }
}
