// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.typespec.http.client.generator.core.postprocessor.implementation;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class CodeFormatterUtilTests {
    @ParameterizedTest
    @ValueSource(strings = { "module-info.java", "src/main/module-info.java" })
    public void moduleInfoFormatting(String fileName) {
        String initial = String.join("\n", "// Copyright (c) Microsoft Corporation. All rights reserved.",
            "// Licensed under the MIT License.", "// Code generated by Microsoft (R) TypeSpec Code Generator.", "",
            "module com.azure.resourcemanager.avs {", "requires transitive com.azure.core.management;",
            "exports com.azure.resourcemanager.avs;", "exports com.azure.resourcemanager.avs.fluent;",
            "exports com.azure.resourcemanager.avs.fluent.models;", "exports com.azure.resourcemanager.avs.models;",
            "opens com.azure.resourcemanager.avs.fluent.models", "to com.azure.core;",
            "opens com.azure.resourcemanager.avs.models", "to com.azure.core;",
            "opens com.azure.resourcemanager.avs.implementation.models to com.azure.core;", "}");
        String expected = String.join("\n", "// Copyright (c) Microsoft Corporation. All rights reserved.",
            "// Licensed under the MIT License.", "// Code generated by Microsoft (R) TypeSpec Code Generator.", "",
            "module com.azure.resourcemanager.avs {", "    requires transitive com.azure.core.management;", "",
            "    exports com.azure.resourcemanager.avs;", "    exports com.azure.resourcemanager.avs.fluent;",
            "    exports com.azure.resourcemanager.avs.fluent.models;",
            "    exports com.azure.resourcemanager.avs.models;", "",
            "    opens com.azure.resourcemanager.avs.fluent.models to com.azure.core;",
            "    opens com.azure.resourcemanager.avs.models to com.azure.core;",
            "    opens com.azure.resourcemanager.avs.implementation.models to com.azure.core;", "}", "");

        List<String> formattingResult = CodeFormatterUtil.formatCode(new HashMap<>(Map.of(fileName, initial)));

        assertEquals(1, formattingResult.size());
        assertEquals(expected, formattingResult.get(0));
    }
}
