using System.IO;

namespace Nodify.Calculator
{
    public static class ProjectManager
    {
        public const string ProjectExtension = ".avep";
        public const string ProjectFilter = "API Visual Executor Project (*.avep)|*.avep";

        public static string ProjectName { get; private set; } = string.Empty;
        public static string ProjectDirectory { get; private set; } = string.Empty;
        public static string ProjectFilePath { get; private set; } = string.Empty;
        public static string DatabasePath { get; private set; } = "MyData.db";

        public static void CreateProject(string name, string directory)
        {
            ProjectName = name;
            ProjectDirectory = directory;
            ProjectFilePath = Path.Combine(directory, name + ProjectExtension);
            DatabasePath = Path.Combine(directory, name + ".db");

            Directory.CreateDirectory(directory);

            // Write a simple project file
            File.WriteAllText(ProjectFilePath, $"{{\"name\":\"{name}\"}}");
        }

        public static void OpenProject(string projectFilePath)
        {
            ProjectFilePath = projectFilePath;
            ProjectDirectory = Path.GetDirectoryName(projectFilePath)!;
            ProjectName = Path.GetFileNameWithoutExtension(projectFilePath);
            DatabasePath = Path.Combine(ProjectDirectory, ProjectName + ".db");
        }
    }
}
