namespace MinicsConsole.Business;

public class DatabaseOperator(
    BasicInfo basicInfo,
    DataBaseSwitch dataBaseSwitch,
    DataBaseCleaner dataBaseCleaner,
    UISender uIConnector, ILog log)
{
    public string? SwitchDataBase()
    {
        if (!dataBaseSwitch.SwitchDataBaseLibrary(out string? newDBName))
            return string.Empty;
        log.Info($"ConfigHub - SwitchDataBase HotSwtich DataBase {newDBName}");
        return newDBName;
    }

    public void ClearDataBase()
    {
        dataBaseCleaner.CleanDB();
        uIConnector.UpdateDataBaseInfo(basicInfo.DBKeepRange, basicInfo.DBClearTime);
    }

    public void UpdateDataBaseRange(int range)
    {
        basicInfo.DBKeepRange = range;
        BaseConfigFileLoader.Save(basicInfo);

        uIConnector.UpdateDataBaseInfo(basicInfo.DBKeepRange, basicInfo.DBClearTime);
    }
}
