
package usda.weru.remoteDataAccess.remoteFiles.inetFile;

import usda.weru.remoteDataAccess.csip.CsipInputControllerStatic;
import usda.weru.remoteDataAccess.csip.CsipLmodUtil;
import usda.weru.remoteDataAccess.csip.CsipLmodUtil.lmodType;
import usda.weru.remoteDataAccess.csip.CsipInputControllerBgCacheIf;

/**
 *
 * @author mhaas
 */
public class CrLmodFile extends InetFile implements InetFileBgIf {
    
    static final long serialVersionUID = 1L;
    
    public CrLmodFile(String name) {
        this (name, lmodType.lmodDefault);
    }
    
    public CrLmodFile(lmodType type) {
        //old version: put back if something breaks
//        this (CsipLmodUtil.getCrLmodName(type), type);
//        It did break the code, reverting to use of above line - LEW
        this (findName(type), type);
    }
    
    public CrLmodFile(String name, lmodType type) {
        super (name, RemoteFileType.CRLMOD);
        controller = CsipInputControllerStatic.getCrLmodController(type);
        controller.setInterfaceName(name);
    }
    
    public CrLmodFile(CrLmodFile parent, String name) {
        super ((InetFile)parent, name);
    }
    
    @Override
    public void doBackgroundCatalog () {
        ((CsipInputControllerBgCacheIf)controller).doBackgroundGetCatalog();
    }

    @Override
    public boolean checkBackgroundDownload() {
        return ((CsipInputControllerBgCacheIf)controller).checkBackgroundGetCatalog();
    }

    @Override
    public boolean checkBackgroundNewFiles() {
        return ((CsipInputControllerBgCacheIf)controller).checkNewFiles();
    }

    @Override
    public CsipInputControllerBgCacheIf getBackgroundPropertyChangeObject() {
        return (CsipInputControllerBgCacheIf)controller;
    }
    
    @Override
    public void clearBackgroundNewFiles () {
        ((CsipInputControllerBgCacheIf)controller).clearNewFiles();
    }
    
    private static String findName(lmodType type) {
        String tempName = CsipLmodUtil.getCrLmodName(type);
        if(tempName.equals("CrLmod Crops") || tempName.equals("CRLMOD Crops") ) {
            return "CRLMOD Crops and Residues";
        } else {
            return tempName;
        }
    }
}
