<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TypeGap.Extensions;
using TypeGap.Util;

namespace TypeGap
{

    public enum ApiParameterMode
    {
        Unspecified = 0,
        FromBody,
        FromUri,
    }

    public enum ApiMethod
    {
        Get,
        Post,
        Delete,
        Patch,
        Put,
    }

    public class ApiControllerDesc
    {
        private string _controllerName;

        public string ControllerName
        {
            get { return _controllerName; }
            set
            {
                _controllerName = value.Replace("Controller", "");
            }
        }

        public string RouteTemplate { get; set; } = "api/[controller]";
        public List<ApiActionDesc> Actions { get; set; } = new List<ApiActionDesc>();

        public ApiActionDesc AddAction(string name, Type returnType, ApiMethod method = ApiMethod.Get, string route = null, IEnumerable<ApiParamDesc> parameters = null)
        {
            var action = new ApiActionDesc();
            action.ActionName = name;

            action.ReturnType = returnType;
            action.Method = method;

            if (!String.IsNullOrWhiteSpace(route))
                action.RouteTemplate = route;

            if (parameters != null)
                action.Parameters.AddRange(parameters);

            Actions.Add(action);
            return action;
        }
    }

    public class ApiActionDesc
    {
        public string ActionName { get; set; }
        public string RouteTemplate { get; set; }
        public ApiMethod Method { get; set; }
        public List<ApiParamDesc> Parameters { get; set; } = new List<ApiParamDesc>();
        public Type ReturnType { get; set; }
    }

    public class ApiParamDesc
    {
        public string ParameterName { get; set; }
        public Type ParameterType { get; set; }
        public bool IsOptional { get; set; }
        public ApiParameterMode Mode { get; set; }
    }

    public class AjaxExecContext
    {
        public string Ajax { get; set; }
        public string Url { get; set; }
        public string Post { get; set; }
        public string HttpMethod { get; set; }
        public string Options { get; set; }
    }

    public class GapApiGeneratorOptions
    {
        public Func<string, string> UrlRewriter = (v) => v;
        public string PromiseType { get; set; } = "Promise";
        public string EssentialsImportPath { get; set; } = "./Ajax";
        public string HeaderText { get; set; }
        public string FooterText { get; set; }
        public string AjaxClassName { get; set; } = "Ajax";
        public string ControllerBaseClass { get; set; }
        public string OptionsClassName { get; set; } = "IExtendedAjaxSettings";
        public Func<AjaxExecContext, string> AjaxExecFn { get; set; } = (c) => $"this.{c.Ajax}.execute({c.Url}, {c.HttpMethod}, {c.Post}, {c.Options})";
        public List<GapInitializer> TypeInitializers { get; set; } = new List<GapInitializer>();
    }

    public class GapApiGenerator
    {
        private readonly TypeConverter _converter;
        private readonly GapApiGeneratorOptions _options;
        private readonly string checkRealFn = "is_real";
        private readonly string initVariableName = "obj";
        private readonly string initIndent = "    ";
        private readonly string ajaxVariableName = "_ajax";

        private readonly string optionsVariableName = "ajaxOptions";

        public GapApiGenerator(TypeConverter converter, string indent, GapApiGeneratorOptions options)
        {
            _converter = converter;<commit_msg>This should be a property not a field<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TypeGap.Extensions;
using TypeGap.Util;

namespace TypeGap
{

    public enum ApiParameterMode
    {
        Unspecified = 0,
        FromBody,
        FromUri,
    }

    public enum ApiMethod
    {
        Get,
        Post,
        Delete,
        Patch,
        Put,
    }

    public class ApiControllerDesc
    {
        private string _controllerName;

        public string ControllerName
        {
            get { return _controllerName; }
            set
            {
                _controllerName = value.Replace("Controller", "");
            }
        }

        public string RouteTemplate { get; set; } = "api/[controller]";
        public List<ApiActionDesc> Actions { get; set; } = new List<ApiActionDesc>();

        public ApiActionDesc AddAction(string name, Type returnType, ApiMethod method = ApiMethod.Get, string route = null, IEnumerable<ApiParamDesc> parameters = null)
        {
            var action = new ApiActionDesc();
            action.ActionName = name;

            action.ReturnType = returnType;
            action.Method = method;

            if (!String.IsNullOrWhiteSpace(route))
                action.RouteTemplate = route;

            if (parameters != null)
                action.Parameters.AddRange(parameters);

            Actions.Add(action);
            return action;
        }
    }

    public class ApiActionDesc
    {
        public string ActionName { get; set; }
        public string RouteTemplate { get; set; }
        public ApiMethod Method { get; set; }
        public List<ApiParamDesc> Parameters { get; set; } = new List<ApiParamDesc>();
        public Type ReturnType { get; set; }
    }

    public class ApiParamDesc
    {
        public string ParameterName { get; set; }
        public Type ParameterType { get; set; }
        public bool IsOptional { get; set; }
        public ApiParameterMode Mode { get; set; }
    }

    public class AjaxExecContext
    {
        public string Ajax { get; set; }
        public string Url { get; set; }
        public string Post { get; set; }
        public string HttpMethod { get; set; }
        public string Options { get; set; }
    }

    public class GapApiGeneratorOptions
    {
        public Func<string, string> UrlRewriter { get; set; } = (v) => v;
        public string PromiseType { get; set; } = "Promise";
        public string EssentialsImportPath { get; set; } = "./Ajax";
        public string HeaderText { get; set; }
        public string FooterText { get; set; }
        public string AjaxClassName { get; set; } = "Ajax";
        public string ControllerBaseClass { get; set; }
        public string OptionsClassName { get; set; } = "IExtendedAjaxSettings";
        public Func<AjaxExecContext, string> AjaxExecFn { get; set; } = (c) => $"this.{c.Ajax}.execute({c.Url}, {c.HttpMethod}, {c.Post}, {c.Options})";
        public List<GapInitializer> TypeInitializers { get; set; } = new List<GapInitializer>();
    }

    public class GapApiGenerator
    {
        private readonly TypeConverter _converter;
        private readonly GapApiGeneratorOptions _options;
        private readonly string checkRealFn = "is_real";
        private readonly string initVariableName = "obj";
        private readonly string initIndent = "    ";
        private readonly string ajaxVariableName = "_ajax";

        private readonly string optionsVariableName = "ajaxOptions";

        public GapApiGenerator(TypeConverter converter, string indent, GapApiGeneratorOptions options)
        {
            _converter = converter;
{'fraction_non_alphanumeric': 0.0902176763703121, 'fraction_numerical': 0.00026226068712300026, 'mean_word_length': 2.2988754325259517, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6313040', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1994, 'n_words': 596}