using System.Text;
using Plate.Templates;

namespace Plate
{
    class Plate
    {
        public Plate()
        {
        }

        internal string make(string[] args)
        {
            switch (args[0].ToLower())
            {
                case "heaps":
                    return buildHeaps(args);
                default:
                    return $"unknown template \"{args[0]}\"";
            }
        }


        private string buildHeaps(string[] args)
        {
            string projName = "HeapsProj";
            if (args.Length == 2){
                projName = args[1];
            }

            string pwd = Directory.GetCurrentDirectory();
            var dirInfo = Directory.CreateDirectory(Path.Join(pwd, projName));

            System.Console.WriteLine(dirInfo);
            dirInfo.CreateSubdirectory("res");
            dirInfo.CreateSubdirectory("src");
            dirInfo.CreateSubdirectory(".vscode");

            File.WriteAllText(Path.Join(dirInfo.Name, "build.hxml"), TemplateHeaps.build_hxml);
            File.WriteAllText(Path.Join(dirInfo.Name, "src", "Main.hx"), TemplateHeaps.main_hx);
            File.WriteAllText(Path.Join(dirInfo.Name, ".vscode", "launch.json"), TemplateHeaps.launch_json);
            File.WriteAllText(Path.Join(dirInfo.Name, ".vscode", "tasks.json"), TemplateHeaps.tasks_json);
            


            return "Created heaps";
        }
    }
}