package exports;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.Writer;
import java.util.List;

import static org.codelutin.i18n.I18n._;
import org.codelutin.math.matrix.*;

import fr.ifremer.isisfish.entities.*;
import fr.ifremer.isisfish.export.Export;
import fr.ifremer.isisfish.types.Date;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.datastore.ResultStorage;

import fr.ifremer.isisfish.util.Doc; // pour pouvoir afficher une aide contextuelle (BUG#1605)

/**
 * ZonesDefinition.java
 *
 * Created: 17 janvier 2007
 *
 * @author bpoussin <bpoussin@labs.libre-entreprise.org>
 * @version $Revision: 1.2 $
 *
 * Last update: $Date: 2007-05-24 09:30:07 $
 * by : $Author: bpoussin $
 */
 @Doc(value="do the doc of class ZoneDefinition")
public class ZonesDefinition implements Export {

    /** to use log facility, just put in your code: log.info("..."); */
    static private Log log = LogFactory.getLog(ZonesDefinition.class);

    public String [] necessaryResult = {
    // put here all necessary result for this rule
    // example: 
    // ResultName.MATRIX_BIOMASS,
    // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
    };

    public String[] getNecessaryResult() {
        return this.necessaryResult;
    }

    public String getExportFilename() {
        return "ZonesDefinition";
    }
    
    public String getExtensionFilename() {
        return ".csv";
    }
    
    public String getDescription() {
        return _("Export cell's zone constitution");
    }

    public void export(SimulationStorage simulation, Writer out) throws Exception {
        List<Zone> zones = simulation.getFisheryRegion().getZone();
        Date lastDate = simulation.getResultStorage().getLastDate();       
        
        for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) {
            for (Zone zone : zones) {
                for (Cell cell : zone.getCell()) {
                    out.write(zone + ";" + cell + ";" + date.getDate() + "\n");
                }
            }
        }
    }

}
