#include "file_header.h"

#include <filesystem>
#include <format>
#include <map>

#include "../common/string_tools.h"

using namespace std;

namespace Generator {

namespace {

// Only the two line-comment styles this project's own generators actually need today
// (see AGENTS.md's doc-comment style rationale, mirrored from buildDocComment/functions.cpp) -
// "/** */"/"///" are still reachable, just not from this built-in table, via a generator.yml
// commentStyle override for a generator whose own default style differs.
const map<string, string>& extensionStyles()
{
    static const map<string, string> styles = {
        // "//" - Kotlin, TypeScript/JS, Go, C/C++, Java, C#, Rust, Swift, Dart.
        { "h", "//" },
        { "hpp", "//" },
        { "cpp", "//" },
        { "cc", "//" },
        { "c", "//" },
        { "cs", "//" },
        { "java", "//" },
        { "js", "//" },
        { "jsx", "//" },
        { "ts", "//" },
        { "tsx", "//" },
        { "go", "//" },
        { "kt", "//" },
        { "kts", "//" },
        { "swift", "//" },
        { "dart", "//" },
        { "rs", "//" },
        // "#" - Ruby, Python, shell, Perl, YAML, TOML.
        { "rb", "#" },
        { "py", "#" },
        { "sh", "#" },
        { "bash", "#" },
        { "pl", "#" },
        { "yml", "#" },
        { "yaml", "#" },
        { "toml", "#" },
    };
    return styles;
}

}

optional<string> commentStyleForExtension(const string& outFileName)
{
    auto ext = filesystem::path(outFileName).extension() | ltrim('.');
    auto it = extensionStyles().find(ext);
    if (it == extensionStyles().end())
        return nullopt;
    return it->second;
}

string defaultHeaderText(const string& generatorName)
{
    return format("Code generated by openapi-yagen ({}). DO NOT EDIT.\nhttps://openapi-yagen.github.io", generatorName);
}

}
