using System;
using StubCore.Configuration;
using StubCore.Plugins.Logging;
using System.Collections.Generic;
using StubCore.Plugins.FileOperations;

namespace StubAP.Models
{
    public class FrontLogicModel
    {
        private readonly ContextLogger _logger = new ContextLogger();

        public FrontLogicModel()
        {
            if (!ValidateFolders())
            {
                _logger.FoldersValidationFault();
            }
        }

        public Dictionary<string, string> GetConfigSet()
        {
            var _list = new Dictionary<string, string>
            {
                {"title", Configuration.SystemTitle },
                {"version", Configuration.SystemVersion },
                {"description", Configuration.SystemDescription }
            };
            
            return _list;
        }

        public bool ValidateFolders()
        {
            var isCreated = true;
            var _filemanager = new FileManager();
            var _filefolders = Configuration.DatabaseFolders;

            if (!_filemanager.ValidateDatabaseFiles(_filefolders))
            {
                isCreated = false;
                _logger.FilesAndFoldersNoCreated();
            }

            return isCreated;
        }

        public Dictionary<string, string> UpdateConfigSet(string title, string description)
        {
            var config = GetConfigSet();
            config["title"] = !String.IsNullOrEmpty(title) ? config["title"] + " - " + title : config["title"];
            config["description"] = !String.IsNullOrEmpty(description) ? config["description"] + " | " + description : config["description"];
            return config;
        }
        
    }
}