// See https://aka.ms/new-console-template for more information

using NJsonSchema.CodeGeneration.TypeScript;
using NSwag;
using NSwag.CodeGeneration.OperationNameGenerators;
using NSwag.CodeGeneration.TypeScript;

var document = OpenApiDocument.FromUrlAsync(("http://localhost:5000/swagger/v1/swagger.json")).Result;

var settings = new TypeScriptClientGeneratorSettings
{
    ClassName = "{controller}Client",
    ClientBaseClass = "AuthorizedApiBase",
    ConfigurationClass = "IConfig",
    GenerateDtoTypes = true,
    UseTransformOptionsMethod = true,
    TypeScriptGeneratorSettings =
    {
        EnumStyle = TypeScriptEnumStyle.Enum,
        DateTimeType = TypeScriptDateTimeType.Date,
        NullValue = TypeScriptNullValue.Null,
        TypeStyle = TypeScriptTypeStyle.Interface,
        GenerateDefaultValues = true,
        MarkOptionalProperties = true,
        TypeScriptVersion = 4.3m
    },
    OperationNameGenerator = new MultipleClientsFromFirstTagAndOperationIdGenerator(),
    Template = TypeScriptTemplate.Fetch,
};

var generatorApiClient = new TypeScriptClientGenerator(document, settings);
var codeApiClient = generatorApiClient.GenerateFile();
File.WriteAllText("ManagingApi.ts", codeApiClient);

var settingsTypes = new TypeScriptClientGeneratorSettings
{
    GenerateDtoTypes = true,
    TypeScriptGeneratorSettings =
    {
        EnumStyle = TypeScriptEnumStyle.Enum,
        DateTimeType = TypeScriptDateTimeType.Date,
        NullValue = TypeScriptNullValue.Null,
        TypeStyle = TypeScriptTypeStyle.Interface,
        GenerateDefaultValues = true,
        MarkOptionalProperties = true,
        TypeScriptVersion = 4.3m
    },
    GenerateClientClasses = false,
    GenerateClientInterfaces = false,
    GenerateOptionalParameters = false,
    GenerateResponseClasses = false,
};

var generatorTypes = new TypeScriptClientGenerator(document, settingsTypes);
var codeTypes = generatorTypes.GenerateFile();
File.WriteAllText("ManagingApiTypes.ts", codeTypes);