"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.llcsharpV2 = void 0;
const codegen_1 = require("@azure-tools/codegen");
const path_1 = require("path");
const project_1 = require("../llcsharp/project");
const resources = `${__dirname}/../../resources`;
async function llcsharpV2(service, state) {
    try {
        const project = await new project_1.Project(service).init(state);
        const transformOutput = async (input) => {
            return await project.state.resolveVariables(input);
        };
        await project.writeFiles(async (fname, content) => project.state.writeFile((0, path_1.join)(project.apifolder, fname), (0, codegen_1.applyOverrides)(content, project.overrides), undefined, 'source-file-csharp'));
        // recursive copy resources
        await (0, codegen_1.copyResources)((0, path_1.join)(resources, 'runtime', 'csharp', 'client'), async (fname, content) => project.state.writeFile((0, path_1.join)(project.runtimefolder, fname), content, undefined, 'source-file-other'), project.overrides);
        await (0, codegen_1.copyResources)((0, path_1.join)(resources, 'runtime', 'csharp', 'pipeline'), async (fname, content) => project.state.writeFile((0, path_1.join)(project.runtimefolder, fname), content, undefined, 'source-file-other'), project.overrides, transformOutput);
        // Note:
        // we are using the Carbon.Json library, but we don't *really* want to expose that as public members where we don't have to
        // and I don't want to make code changes in the source repository, so I can keep merging from upstream as simple as possible.
        // so, we're converting as much as possible to internal, and exposing only what must be exposed to make the code compile.
        await (0, codegen_1.copyResources)((0, path_1.join)(resources, 'runtime', 'csharp', 'json'), async (fname, content) => project.state.writeFile((0, path_1.join)(project.runtimefolder, fname), content, undefined, 'source-file-other'), {
            ...project.overrides,
            'public': 'internal',
            'internal (.*) class JsonNumber': 'public $1 class JsonNumber',
            'internal (.*) class JsonObject': 'public $1 class JsonObject',
            'internal (.*) class JsonNode': 'public $1 class JsonNode',
            'internal (.*) class JsonString': 'public $1 class JsonString',
            'internal (.*) class XNodeArray': 'public $1 class XNodeArray',
            'internal (.*) class JsonArray': 'public $1 class JsonArray',
            'internal(.*) class JsonTokenizer': 'public$1 class JsonTokenizer',
            'internal(.*) class JsonParser': 'public$1 class JsonParser',
            'internal(.*) class TokenReader': 'public$1 class TokenReader',
            'internal(.*) class SourceReader': 'public$1 class SourceReader',
            'internal(.*) class (.*)Converter': 'public$1 class $2Converter',
            'internal(.*) interface IJsonSerializable': 'public$1 interface IJsonSerializable',
            'internal override string ToString': 'public override string ToString',
            'internal void Add\\(': 'public void Add(',
            'internal bool ContainsKey\\(': 'public bool ContainsKey(',
            'internal bool Remove\\(': 'public bool Remove(',
            'internal bool TryGetValue\\(': 'public bool TryGetValue(',
            'internal (.*) JsonNode this\\[': 'public $1 JsonNode this[',
            'internal ICollection<JsonNode> Values': 'public ICollection<JsonNode> Values',
            'internal ICollection<string> Keys': 'public ICollection<string> Keys',
            'internal bool IsReadOnly': 'public bool IsReadOnly',
            'internal (.*) int Count': 'public $1 int Count',
            'internal bool Contains\\(': 'public bool Contains(',
            'internal(.*) bool Equals': 'public$1 bool Equals',
            'internal (.*) int GetHashCode': 'public $1 int GetHashCode',
            'internal void Dispose': 'public void Dispose',
            'internal (.*) operator': 'public $1 operator',
            'internal object FromJson\\(': 'public object FromJson(',
            'internal JsonNode ToJson\\(': 'public JsonNode ToJson(',
        });
        if (project.xmlSerialization) {
            await (0, codegen_1.copyResources)((0, path_1.join)(resources, 'runtime', 'csharp', 'xml'), async (fname, content) => project.state.writeFile((0, path_1.join)(project.runtimefolder, fname), content, undefined, 'source-file-other'), project.overrides);
        }
        if (project.azure) {
            await (0, codegen_1.copyResources)((0, path_1.join)(resources, 'runtime', 'csharp.azure'), async (fname, content) => project.state.writeFile((0, path_1.join)(project.runtimefolder, fname), content, undefined, 'source-file-other'), project.overrides);
        }
    }
    catch (E) {
        if (E instanceof Error) {
            console.error(`${__filename} - ${E.stack}/${E.message}`);
        }
        throw E;
    }
}
exports.llcsharpV2 = llcsharpV2;
//# sourceMappingURL=llcsharp-v2.js.map