package Visual_DVM_2021.Passes.All;
import Common.Utils.Utils_;
import _VisualDVM.GlobalData.GlobalDatabase;
import _VisualDVM.Global;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.FileObject.DirInfo;
import _VisualDVM.GlobalData.FileObject.DirInfosDataSet;
import _VisualDVM.GlobalData.Settings.SettingName;
import Common.Passes.Pass;

import java.io.File;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class GetOldBugReports extends Pass<DirInfosDataSet> {
    @Override
    protected boolean canStart(Object... args) throws Exception {
        target = new DirInfosDataSet();
        return true;
    }
    @Override
    protected boolean needsAnimation() {
        return true;
    }
    @Override
    protected void body() throws Exception {
        File workspace = Global.visualiser.getWorkspace();
        File[] files = workspace.listFiles(pathname -> pathname.isDirectory() && pathname.getName().toLowerCase().startsWith("bugreport_"));
        if (files != null) {
            //---
            Calendar c = new GregorianCalendar();
            c.setTimeInMillis(System.currentTimeMillis());
            c.add(Calendar.MONTH, -(Global.mainModule.getDb()).settings.get(SettingName.BugReportsAgeLimit).toInt32());
            Date date = c.getTime();
            System.out.println(date);
            long border = date.getTime();
            //--
            for (File file : files) {
                ShowMessage2(file.getName());
                long mdate = Utils.getNewestFileDate(file);
                if (mdate <= border) {
                    DirInfo d = new DirInfo(file, mdate);
                    target.put(d.getPK(), d);
                }
            }
        }
    }
}
