/*
 * Copyright
 *   2007 axYus - www.axyus.com
 *   2009 C.Marchand - christophe.marchand@axyus.com
 *
 * This file is part of XEMELIOS.
 *
 * XEMELIOS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * XEMELIOS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package fr.gouv.finances.dgfip.xemelios.web.imports;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author chm
 */
public class Import {
    public static final transient String SELECT = "SELECT UTI_LOGIN,IMPORT_ID,FILE_NAME,FILE_TYPE,SUBMIT_DATE,END_DATE,STATUS,COLLECTIVITE,BUDGET,COLLECTIVITE_LIB,BUDGET_LIB,ERROR_MESSAGE FROM XEM_IMPORTS";
    private String importId;
    private String userLogin;
    private String fileName;
    private String fileType;
    private int status;
    private String collectiviteId;
    private String collectiviteLib;
    private String budgetId;
    private String budgetLib;
    private List<ImportFile> importFiles;
    private Timestamp submitDate;
    private Timestamp endDate;
    private String errorMessage;

    public Import() {
        super();
        importFiles = new ArrayList<ImportFile>();
    }
    public Import(ResultSet rs) throws SQLException {
        this();
        int i=1;
        userLogin = rs.getString(i++);
        importId = rs.getString(i++);
        fileName=rs.getString(i++);
        fileType=rs.getString(i++);
        try {
            submitDate=rs.getTimestamp(i++);
        } catch(SQLException sqlEx) {}
        try {
            endDate=rs.getTimestamp(i++);
        } catch(SQLException sqlEx) {}
        status=rs.getInt(i++);
        collectiviteId=rs.getString(i++);
        budgetId=rs.getString(i++);
        collectiviteLib=rs.getString(i++);
        budgetLib=rs.getString(i++);
        errorMessage=rs.getString(i++);
    }

    public String getBudgetId() {
        return budgetId;
    }

    public void setBudgetId(String budgetId) {
        this.budgetId = budgetId;
    }

    public String getBudgetLib() {
        return budgetLib;
    }

    public void setBudgetLib(String budgetLib) {
        this.budgetLib = budgetLib;
    }

    public String getCollectiviteId() {
        return collectiviteId;
    }

    public void setCollectiviteId(String collectiviteId) {
        this.collectiviteId = collectiviteId;
    }

    public String getCollectiviteLib() {
        return collectiviteLib;
    }

    public void setCollectiviteLib(String collectiviteLib) {
        this.collectiviteLib = collectiviteLib;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFileType() {
        return fileType;
    }

    public void setFileType(String fileType) {
        this.fileType = fileType;
    }

    public List<ImportFile> getImportFiles() {
        return importFiles;
    }

    public void setImportFiles(List<ImportFile> importFiles) {
        this.importFiles = importFiles;
    }

    public String getImportId() {
        return importId;
    }

    public void setImportId(String importId) {
        this.importId = importId;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getUserLogin() {
        return userLogin;
    }

    public void setUserLogin(String userLogin) {
        this.userLogin = userLogin;
    }

    public Timestamp getEndDate() {
        return endDate;
    }

    public void setEndDate(long endDate) {
        this.endDate = new Timestamp(endDate);
    }

    public Timestamp getSubmitDate() {
        return submitDate;
    }

    public void setSubmitDate(long submitDate) {
        this.submitDate = new Timestamp(submitDate);
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    
    public void addImportFile(ImportFile importFile) {
        importFiles.add(importFile);
    }
    public String getStrStatus() {
        return ImportHelper.IMPORT_STATUS_LIB[getStatus()];
    }
}
