package org.lodder.subtools.multisubdownloader.actions;

import java.util.Collections;
import java.util.List;

import org.lodder.subtools.multisubdownloader.lib.SubtitleSelection;
import org.lodder.subtools.multisubdownloader.lib.control.subtitles.sorting.SubtitleComparator;
import org.lodder.subtools.multisubdownloader.settings.model.Settings;
import org.lodder.subtools.sublibrary.logging.Logger;
import org.lodder.subtools.sublibrary.model.Release;
import org.lodder.subtools.sublibrary.model.Subtitle;
import org.lodder.subtools.sublibrary.model.SubtitleMatchType;

public class SubtitleSelectionAction {

  private SubtitleSelection subtitleSelection;
  private Settings settings;

  public SubtitleSelectionAction(Settings settings) {
    this.settings = settings;
  }

  public void setSubtitleSelection(SubtitleSelection subtitleSelection) {
    this.subtitleSelection = subtitleSelection;
  }

  public int subtitleSelection(final Release release,
      final boolean subtitleSelectionDialog) {

    // Sort subtitles by score
    Collections.sort(release.getMatchingSubs(), new SubtitleComparator());

    if (release.getMatchingSubs().size() > 0) {
      Logger.instance.debug("determineWhatSubtitleDownload for videoFile: " + release.getFilename()
          + " # found subs: " + release.getMatchingSubs().size());
      if (settings.isOptionsAlwaysConfirm()) {
        return subtitleSelection.getUserInput(release);
      } else if (release.getMatchingSubs().size() == 1
          && release.getMatchingSubs().get(0).getSubtitleMatchType() == SubtitleMatchType.EXACT) {
        Logger.instance.debug("determineWhatSubtitleDownload: Exact Match");
        return 0;
      } else if (release.getMatchingSubs().size() > 1) {
        Logger.instance.debug("determineWhatSubtitleDownload: Multiple subs detected");

        // Automatic selection
        List<Subtitle> shortlist =
            subtitleSelection.getAutomaticSelection(release.getMatchingSubs());
        release.setMatchingSubs(shortlist);
        // automatic selection results in 1 result
        if (shortlist.size() == 1) return 0;
        // nothing match the minimum automatic selection value
        if (shortlist.size() == 0) return -1;

        // still more then 1 subtitle, let the user decide!
        if (subtitleSelectionDialog) {
          Logger.instance.debug("determineWhatSubtitleDownload: Select subtitle with dialog");
          return subtitleSelection.getUserInput(release);
        } else {
          Logger.instance.log("Multiple subs detected for: " + release.getFilename()
              + " Unhandleable for CMD! switch to GUI"
              + " or use '--selection' as switch in de CMD");
        }
      } else if (release.getMatchingSubs().size() == 1) {
        Logger.instance.debug("determineWhatSubtitleDownload: only one sub taking it!!!!");
        return 0;
      }
    }
    Logger.instance.debug("determineWhatSubtitleDownload: No subs found for: "
        + release.getFilename());
    return -1;
  }
}

@@ -344,62 +344,8 @@
 gs;%0A
-import org.lodder.subtools.sublibrary.logging.Logger;%0A
 impo
@@ -514,47 +514,200 @@
 pe;%0A
-%0Apublic class SubtitleSelectionAction %7B
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Apublic class SubtitleSelectionAction %7B%0A%0A  private static final Logger LOGGER = LoggerFactory.getLogger(SubtitleSelectionAction.class);
 %0A%0A  
@@ -1050,22 +1050,16 @@
 release,
-%0A     
  final b
@@ -1251,38 +1251,29 @@
 0) %7B%0A      L
-ogger.instance
+OGGER
 .debug(%22dete
@@ -1317,65 +1317,66 @@
 le: 
-%22 + release.getFilename()%0A          + %22 # found subs: %22 +
+%5B%7B%7D%5D # found subs: %5B%7B%7D%5D%22,%0A          release.getFilename(),
  rel
@@ -1669,38 +1669,29 @@
  %7B%0A        L
-ogger.instance
+OGGER
 .debug(%22dete
@@ -1812,38 +1812,29 @@
  %7B%0A        L
-ogger.instance
+OGGER
 .debug(%22dete
@@ -2389,38 +2389,29 @@
 %0A          L
-ogger.instance
+OGGER
 .debug(%22dete
@@ -2558,99 +2558,86 @@
    L
-ogger.instance.log(%22Multiple subs detected for: %22 + release.getFilename()%0A              + %22
+OGGER%0A              .info(%0A                  %22Multiple subs detected for: %5B%7B%7D%5D
  Unh
@@ -2672,27 +2672,8 @@
  GUI
-%22%0A              + %22
  or 
@@ -2710,16 +2710,57 @@
  de CMD%22
+,%0A                  release.getFilename()
 );%0A     
@@ -2827,38 +2827,29 @@
  %7B%0A        L
-ogger.instance
+OGGER
 .debug(%22dete
@@ -2946,22 +2946,13 @@
    L
-ogger.instance
+OGGER
 .deb
@@ -3007,21 +3007,16 @@
  for
-: %22%0A        +
+  %5B%7B%7D%5D%22,
  rel

Convert SubtitleSelectionAction from old logger to new LOGGER slf4j