package com.capgemini.reports.optimized.r23report;

import com.capgemini.framework.common.SettingsHelper;
import com.capgemini.framework.teamcenter.exceptions.KurtException;
import com.capgemini.reports.optimized.Folder;
import com.capgemini.reports.optimized.OptimizedFolder;
import com.capgemini.reports.reports.parameters.ProductUnit;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class OptimizedR23Folder implements OptimizedFolder {
  private static final Path PATH = Paths.get(SettingsHelper.getOptimizedFolderR23());

  @Override
  public boolean configurationHasNotChanged(final ProductUnit productUnit) throws KurtException {
    Folder folder = new Folder(PATH);
    try {
      return folder.exist() && !folder.isEmpty() && !new OptimizedR23File(folder.mostRecentFile()).contains(productUnit);
    }
    catch (IOException e) {
      throw new KurtException(e.getMessage(), e);
    }
  }
}
