﻿using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace IntegratedJs
{
    public class JsDoc
    {
        public string Author { get; set; }
        public string Constructor { get; set; }
        public string Exception { get; set; }
        public string Return { get; set; }
        public List<Param> Param { get; set; }

        public JsDoc()
        {
            Param = new List<Param>();
        }

        public static JsDoc Parse(string src)
        {
            var p = @"\*\s*@(?<name>\w+)(?<args>.*)";
            var m = Regex.Matches(src, p);
            var ret = new JsDoc();

            foreach (Match item in m)
            {
                if(item.Success)
                {
                    var name = item.Groups["name"].Value;
                    var args = item.Groups["args"].Value;

                    switch (name)
                    {
                        case "author":
                            ret.Author = args;
                            break;
                        case "constructor":
                            ret.Constructor = args;
                            break;
                        case "Exception":
                            ret.Exception = args;
                            break;
                        case "return":
                            ret.Return = args;
                            break;

                        default:
                            break;
                    }
                }
            }

            return ret;
        }
    }

    public class Param
    {
        public string Name { get; set; }
        public string Type { get; set; }
    }
}