package net.cserny.videosmover.service;

import net.cserny.videosmover.helper.StaticPathsProvider;
import net.cserny.videosmover.model.Video;
import net.cserny.videosmover.service.observer.VideoAdjustmentObserver;
import net.cserny.videosmover.service.parser.VideoNameParser;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;
import java.util.Set;

@Singleton
public class OutputResolver {

    private Set<VideoNameParser> nameParserList;

    @Inject
    public OutputResolver(Set<VideoNameParser> nameParserList) {
        this.nameParserList = nameParserList;
    }

    public void resolve(Video video, List<VideoAdjustmentObserver> observers) {
        String resolvedName = video.getInputFolderName();
        if (resolvedName == null) {
            resolvedName = video.getInputFolderNameFromFileName();
        }
        video.setOutputFolderName(resolvedName);

        String outputPathWithoutFolder = null;
        switch (video.getVideoType()) {
            case MOVIE:
                outputPathWithoutFolder = StaticPathsProvider.getMoviesPath();
                break;
            case TVSHOW:
                outputPathWithoutFolder = StaticPathsProvider.getTvShowsPath();
                break;
        }
        video.setOutputPath(StaticPathsProvider.getJoinedPathString(outputPathWithoutFolder,
                resolvedName, video.getFileName()));

        // TODO: improve this, 3 parser for movie and 3 for Tv, more OOP
        for (VideoNameParser videoNameParser : nameParserList) {
            switch (video.getVideoType()) {
                case MOVIE:
                    videoNameParser.parseMovie(video, observers);
                    break;
                case TVSHOW:
                    videoNameParser.parseTvShow(video, observers);
                    break;
            }
        }
    }
}

@@ -897,25 +897,24 @@
 dName);%0A
-%0A
         
 String o
@@ -909,497 +909,185 @@
     
-String outputPathWithoutFolder = null;%0A        switch (video.getVideoType()) %7B%0A            case MOVIE:%0A                outputPathWithoutFolder = StaticPathsProvider.getMoviesPath(
+adjustOutputFolderName(video, observers);%0A        adjustOutputPath(video
 );%0A    
-  
-          break;%0A            case TVSHOW:%0A                outputPathWithoutFolder = StaticPathsProvider.getTvShowsPath();%0A                break;%0A        %7D%0A        video.setOutputPath(StaticPathsProvider.getJoinedPathString(outputPathWithoutFolder,%0A                resolvedName, video.getFileName()));%0A
+%7D%0A%0A    private void adjustOutputFolderName(Video video, List%3CVideoAdjustmentObserver%3E observers) %7B
 %0A   
@@ -1538,11 +1538,579 @@
  %7D%0A    %7D
+%0A%0A    private void adjustOutputPath(Video video) %7B%0A        String outputPathWithoutFolder = null;%0A        switch (video.getVideoType()) %7B%0A            case MOVIE:%0A                outputPathWithoutFolder = StaticPathsProvider.getMoviesPath();%0A                break;%0A            case TVSHOW:%0A                outputPathWithoutFolder = StaticPathsProvider.getTvShowsPath();%0A                break;%0A        %7D%0A        video.setOutputPath(StaticPathsProvider.getJoinedPathString(outputPathWithoutFolder,%0A                video.getOutputFolderName(), video.getFileName()));%0A    %7D
 %0A%7D%0A

fix outputResolver order