package usda.weru.remoteDataAccess.csip;

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import usda.weru.util.About;

/**
 *
 * @author mhaas
 */
public class CsipLmodUtil {
    
    protected final static String LmodNameMan = "Lmod Managements";
    protected final static String LmodNameOp = "Lmod Operations";
    protected final static String LmodNameCrop = "Lmod Crops";
    protected final static String LmodNameSoil = "Soils";
    // These don't seem to be used for anything more than labels, but just in case CKM
    protected final static String CrLmodNameMan = "CRLMOD Managements";
    protected final static String CrLmodNameOp = "CRLMOD Operations";
    protected final static String CrLmodNameCrop = "CRLMOD Crops and Residues";
    protected final static String CrLmodNameCropResidue = "CRLMOD Residues";
    //protected final static String CrLmodNameCropResidue = "Residue";
    public final static String CsipNameSoil = "CSIP Soil Service";
    public final static String CsipNamePrism = "CSIP Prism Service";
    
    public final static String WepsCacheDirNameMan = CrLmodNameMan;
    public final static String WepsCacheDirNameOp = CrLmodNameOp;
    public final static String WepsCacheDirNameCrop = CrLmodNameCrop;
    public final static String WepsCacheDirNameCropResidue = CrLmodNameCropResidue;
    public final static String WepsCacheDirNameSoil = "Soils";
    public final static String WepsCacheDirNamePrism = "Prism";
    
    public enum lmodType {
        lmodDefault,
        lmodManagement,
        lmodCrop,
        lmodCropResidue,
        lmodOperation
    };
    
    public static String getLmodName (lmodType type) {
        switch (type) {
            case lmodCrop:
                return LmodNameCrop;
            case lmodCropResidue:
                return "";
            case lmodOperation:
                return LmodNameOp;
            case lmodManagement:
                return LmodNameMan;
        }
        return "";
    }
    
    public static String getCrLmodName (lmodType type) {
        switch (type) {
            case lmodCrop:
                return CrLmodNameCrop;
            case lmodCropResidue:
                return CrLmodNameCropResidue;
            case lmodOperation:
                return CrLmodNameOp;
            case lmodManagement:
                return CrLmodNameMan;
        }
        return "";
    }
    
    //
    // Maybe not the most logical place for this method,
    // but this location at least gets it close to the
    // crlmod soils classes
    //
    public static void resetCrLmodSoilCacheFiles () {
        File f;
        f = new File (About.getWepsCacheDir().getAbsolutePath() + "/" + CsipLmodUtil.WepsCacheDirNameSoil + "/soilCache.properties");
        FileUtils.deleteQuietly(f);
        f = new File (About.getWepsCacheDir().getAbsolutePath() + "/" + CsipLmodUtil.WepsCacheDirNameSoil + "/CSIP Soil Service.idx");
        FileUtils.deleteQuietly(f);
        f = new File (About.getWepsCacheDir().getAbsolutePath() + "/" + CsipLmodUtil.WepsCacheDirNameSoil + "/CSIP Soil Service.catalog");
        FileUtils.deleteQuietly(f);
        
        clearCrLmodSoilCacheTmpDir();
    }
    
    public static void clearCrLmodSoilCacheTmpDir () {
        File f = new File (About.getWepsCacheDir().getAbsolutePath() + "/SoilsTmp");
        try {
            FileUtils.deleteDirectory(f);
        } catch (IOException ex) {
        }        
    }
}
