using Insight.Database;
using System.Data;

namespace PlanTempus.Database.NavigationSystem
{
    internal class Setup
    {

        private readonly IDbConnection _db;

        public Setup(IDbConnection db)
        {
            _db = db;
        }
        public void CreateSystem()
        {
            //await CreateNavigationLinkTemplatesTable(schema);
            //await CreateNavigationLinkTemplateTranslationsTable(schema);
        }

        private async Task CreateNavigationLinkTemplatesTable()
        {
            var sql = $@"
           CREATE TABLE IF NOT EXISTS navigation_link_templates (
               id SERIAL PRIMARY KEY,
               parent_id INTEGER NULL,
               url VARCHAR(500) NOT NULL,
               permission_id INTEGER NULL,
               icon VARCHAR(100) NULL,
               default_order INTEGER NOT NULL,
               FOREIGN KEY (permission_id) REFERENCES permissions(id),
               FOREIGN KEY (parent_id) REFERENCES navigation_link_templates(id)
           )";
            await _db.ExecuteAsync(sql);
        }

        private async Task CreateNavigationLinkTemplateTranslationsTable(string schema)
        {
            var sql = $@"
           CREATE TABLE IF NOT EXISTS navigation_link_template_translations (
               id SERIAL PRIMARY KEY,
               template_id INTEGER NOT NULL,
               language VARCHAR(10) NOT NULL,
               display_name VARCHAR(100) NOT NULL,
               FOREIGN KEY (template_id) REFERENCES navigation_link_templates(id)
           )";
            await _db.ExecuteAsync(sql);
        }
    }
}
