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

package com.azure.resourcemanager.orbital.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.orbital.fluent.models.SpacecraftInner;
import com.azure.resourcemanager.orbital.models.Direction;
import com.azure.resourcemanager.orbital.models.Polarization;
import com.azure.resourcemanager.orbital.models.SpacecraftLink;
import com.azure.resourcemanager.orbital.models.SpacecraftsPropertiesProvisioningState;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class SpacecraftInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SpacecraftInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"provisioningState\":\"failed\",\"noradId\":\"jnchgej\",\"titleLine\":\"podmailzydehojwy\",\"tleLine1\":\"huxinpmqnj\",\"tleLine2\":\"qwixjspro\",\"links\":[{\"name\":\"cputegjvwmfdats\",\"centerFrequencyMHz\":58.022396,\"bandwidthMHz\":80.04477,\"direction\":\"Downlink\",\"polarization\":\"linearVertical\",\"authorizations\":[]},{\"name\":\"hulsuuvmkjozkrwf\",\"centerFrequencyMHz\":13.198918,\"bandwidthMHz\":30.317991,\"direction\":\"Downlink\",\"polarization\":\"LHCP\",\"authorizations\":[]}]},\"location\":\"slwejdpvw\",\"tags\":{\"j\":\"qpsoacctazak\",\"yffdfdos\":\"ahbc\"},\"id\":\"gexpaojakhmsbz\",\"name\":\"hcrzevd\",\"type\":\"hlxaolthqtr\"}")
                .toObject(SpacecraftInner.class);
        Assertions.assertEquals("slwejdpvw", model.location());
        Assertions.assertEquals("qpsoacctazak", model.tags().get("j"));
        Assertions.assertEquals(SpacecraftsPropertiesProvisioningState.FAILED, model.provisioningState());
        Assertions.assertEquals("jnchgej", model.noradId());
        Assertions.assertEquals("podmailzydehojwy", model.titleLine());
        Assertions.assertEquals("huxinpmqnj", model.tleLine1());
        Assertions.assertEquals("qwixjspro", model.tleLine2());
        Assertions.assertEquals("cputegjvwmfdats", model.links().get(0).name());
        Assertions.assertEquals(58.022396f, model.links().get(0).centerFrequencyMHz());
        Assertions.assertEquals(80.04477f, model.links().get(0).bandwidthMHz());
        Assertions.assertEquals(Direction.DOWNLINK, model.links().get(0).direction());
        Assertions.assertEquals(Polarization.LINEAR_VERTICAL, model.links().get(0).polarization());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SpacecraftInner model =
            new SpacecraftInner()
                .withLocation("slwejdpvw")
                .withTags(mapOf("j", "qpsoacctazak", "yffdfdos", "ahbc"))
                .withProvisioningState(SpacecraftsPropertiesProvisioningState.FAILED)
                .withNoradId("jnchgej")
                .withTitleLine("podmailzydehojwy")
                .withTleLine1("huxinpmqnj")
                .withTleLine2("qwixjspro")
                .withLinks(
                    Arrays
                        .asList(
                            new SpacecraftLink()
                                .withName("cputegjvwmfdats")
                                .withCenterFrequencyMHz(58.022396f)
                                .withBandwidthMHz(80.04477f)
                                .withDirection(Direction.DOWNLINK)
                                .withPolarization(Polarization.LINEAR_VERTICAL),
                            new SpacecraftLink()
                                .withName("hulsuuvmkjozkrwf")
                                .withCenterFrequencyMHz(13.198918f)
                                .withBandwidthMHz(30.317991f)
                                .withDirection(Direction.DOWNLINK)
                                .withPolarization(Polarization.LHCP)));
        model = BinaryData.fromObject(model).toObject(SpacecraftInner.class);
        Assertions.assertEquals("slwejdpvw", model.location());
        Assertions.assertEquals("qpsoacctazak", model.tags().get("j"));
        Assertions.assertEquals(SpacecraftsPropertiesProvisioningState.FAILED, model.provisioningState());
        Assertions.assertEquals("jnchgej", model.noradId());
        Assertions.assertEquals("podmailzydehojwy", model.titleLine());
        Assertions.assertEquals("huxinpmqnj", model.tleLine1());
        Assertions.assertEquals("qwixjspro", model.tleLine2());
        Assertions.assertEquals("cputegjvwmfdats", model.links().get(0).name());
        Assertions.assertEquals(58.022396f, model.links().get(0).centerFrequencyMHz());
        Assertions.assertEquals(80.04477f, model.links().get(0).bandwidthMHz());
        Assertions.assertEquals(Direction.DOWNLINK, model.links().get(0).direction());
        Assertions.assertEquals(Polarization.LINEAR_VERTICAL, model.links().get(0).polarization());
    }

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