package org.dbflute.intro.app.logic.document.decomment;

import java.util.List;

import javax.annotation.Resource;

import org.dbflute.infra.doc.decomment.DfDecoMapFile;
import org.dbflute.infra.doc.decomment.DfDecoMapPickup;
import org.dbflute.infra.doc.decomment.DfDecoMapPiece;
import org.dbflute.intro.app.logic.document.DocumentAuthorLogic;
import org.dbflute.intro.app.logic.intro.IntroPhysicalLogic;
import org.dbflute.optional.OptionalThing;

/**
 * @author cabos
 * @author hakiba
 * @author jflute
 */
public class DocumentDecommentPhysicalLogic {

    // ===================================================================================
    //                                                                          Definition
    //                                                                          ==========
    // done cabos shugyo++: move it to infra's decomment classes, file name and path handling by jflute (2017/11/11)
    // TODO cabos why package scope? by jflute (2017/11/19)
    // TODO cabos instance variable should be under Attribute tag comment by jflute (2017/11/19)
    DfDecoMapFile decoMapFile = new DfDecoMapFile();

    // ===================================================================================
    //                                                                           Attribute
    //                                                                           =========
    // done cabos move this above logic DI variables, framework component should be top (jflute policy...) by jflute (2017/11/11)
    @Resource
    private IntroPhysicalLogic introPhysicalLogic;
    @Resource
    private DocumentAuthorLogic documentAuthorLogic;

    // ===================================================================================
    //                                                                           Piece Map
    //                                                                           =========
    public void saveDecommentPiece(String clientProject, DfDecoMapPiece decoMapPiece) {
        decoMapFile.writePiece(buildClientPath(clientProject), decoMapPiece);
    }

    // ===================================================================================
    //                                                                          Pickup Map
    //                                                                          ==========
    // done hakiba tag comment: Pickup Map by jflute (2017/08/17)
    public DfDecoMapPickup readMergedPickup(String clientProject) {
        List<DfDecoMapPiece> pieces = readDecommentPiece(clientProject);
        OptionalThing<DfDecoMapPickup> pickupOpt = readDecommentPickup(clientProject);
        return decoMapFile.merge(pickupOpt, pieces);
    }

    // done hakoba public on demand, so private now by jflute (2017/08/17)
    private List<DfDecoMapPiece> readDecommentPiece(String clientProject) {
        // done hakiba support no-existing directory by jflute (2017/09/28)
        return decoMapFile.readPieceList(buildClientPath(clientProject));
    }

    private OptionalThing<DfDecoMapPickup> readDecommentPickup(String clientProject) {
        // done hakiba support no-existing directory or file by jflute (2017/09/28)
        return decoMapFile.readPickup(buildClientPath(clientProject));
    }

    // ===================================================================================
    //                                                                              Author
    //                                                                              ======
    public String getAuthor() {
        return documentAuthorLogic.getAuthor();
    }

    private String buildClientPath(String clientProject) {
        return introPhysicalLogic.buildClientPath(clientProject);
    }
}

@@ -563,600 +563,117 @@
  // 
-===================================================================================%0A    //                                                                          Definition%0A    //                                                                          ==========%0A    // done cabos shugyo++: move it to infra's decomment classes, file name and path handling by jflute (2017/11/11)%0A    // TODO cabos why package scope? by jflute (2017/11/19)%0A    // TODO cabos instance variable should be under Attribute tag comment by jflute (2017/11/19)%0A    DfDecoMapFile decoMapFile = new DfDecoMapFile();
+done cabos shugyo++: move it to infra's decomment classes, file name and path handling by jflute (2017/11/11)
 %0A%0A  
@@ -1073,16 +1073,238 @@
 /11/11)%0A
+    // TODO done cabos why package scope? by jflute (2017/11/19)%0A    // TODO done cabos instance variable should be under Attribute tag comment by jflute (2017/11/19)%0A    DfDecoMapFile _decoMapFile = new DfDecoMapFile();%0A%0A
     @Res
@@ -1797,16 +1797,17 @@
         
+_
 decoMapF
@@ -2449,32 +2449,33 @@
 %0A        return 
+_
 decoMapFile.merg
@@ -2737,32 +2737,33 @@
 %0A        return 
+_
 decoMapFile.read
@@ -2975,32 +2975,32 @@
 te (2017/09/28)%0A
-
         return d
@@ -2998,16 +2998,17 @@
  return 
+_
 decoMapF

resolve todo