// Path: src/main/java/org/cri/redmetrics/dao/PlayerDao.java
// public class PlayerDao extends EntityDao<Player> {
//     
//     @Inject
//     public PlayerDao(ConnectionSource connectionSource) throws SQLException {
//         super(connectionSource, Player.class);
//     }
// 
//     public Player findByEmail(String email) {
//         try {
//             if (email == null) return null;
//             List<Player> players = orm.queryForEq("email", email);
//             assert players.size() <= 1; // email should be unique
//             if (players.isEmpty()) return null;
//             else return players.get(0);
//         } catch (SQLException e) {
//             throw new DbException(e);
//         }
//     }
// 
// }
// 
// Path: src/main/java/org/cri/redmetrics/model/Event.java
// @Data
// @DatabaseTable(tableName = "events")
// @NoArgsConstructor
// @AllArgsConstructor
// @EqualsAndHashCode(callSuper = true)
// public class Event extends ProgressData {
// 
//     @DatabaseField(persisterClass = IntegerArrayPersister.class, columnDefinition = "integer[]")
//     private Integer[] coordinates;
// 
// }


import au.com.bytecode.opencsv.CSVWriter;
import com.google.inject.Inject;
import org.cri.redmetrics.dao.PlayerDao;
import org.cri.redmetrics.model.Event;
import java.util.List;
import java.util.Map;
package org.cri.redmetrics.csv;



/**
 * Created by himmelattack on 12/02/15.
 */
public class EventCsvEntityConverter implements CsvEntityConverter<Event> {
    private PlayerDao playerDao;

    @Inject
    public EventCsvEntityConverter(PlayerDao playerDao) {
        this.playerDao = playerDao;
    }

    @Override
    public void write(CSVWriter csvWriter, List<Event> models) {
        String[] staticColumnNames = {
                "id",
                "serverTime",
                "userTime",
                "gameVersion",
                "playerId",
                "playerBirthdate",
                "playerRegion",
                "playerCountry",
                "playerGender",
                "playerExternalId",
                "playerCustomData",
                "type",
                "coordinates",
                "section",
        };

        CsvHelper.UnpackedCustomData unpackedCustomData = CsvHelper.unpackCustomData(models);

        String[] customDataColumnNames = unpackedCustomData.columnNames.toArray(new String[0]);
        String[] allColumnNames = CsvHelper.concatenateArrays(staticColumnNames, customDataColumnNames);

        csvWriter.writeNext(allColumnNames);

        // Write out rows
// Path: src/main/java/org/cri/redmetrics/dao/PlayerDao.java
// public class PlayerDao extends EntityDao<Player> {
//     
//     @Inject
//     public PlayerDao(ConnectionSource connectionSource) throws SQLException {
//         super(connectionSource, Player.class);
//     }
// 
//     public Player findByEmail(String email) {
//         try {
//             if (email == null) return null;
//             List<Player> players = orm.queryForEq("email", email);
//             assert players.size() <= 1; // email should be unique
//             if (players.isEmpty()) return null;
//             else return players.get(0);
//         } catch (SQLException e) {
//             throw new DbException(e);
//         }
//     }
// 
// }
// 
// Path: src/main/java/org/cri/redmetrics/model/Event.java
// @Data
// @DatabaseTable(tableName = "events")
// @NoArgsConstructor
// @AllArgsConstructor
// @EqualsAndHashCode(callSuper = true)
// public class Event extends ProgressData {
// 
//     @DatabaseField(persisterClass = IntegerArrayPersister.class, columnDefinition = "integer[]")
//     private Integer[] coordinates;
// 
// }


// Path: src/main/java/org/cri/redmetrics/csv/EventCsvEntityConverter.java
import au.com.bytecode.opencsv.CSVWriter;
import com.google.inject.Inject;
import org.cri.redmetrics.dao.PlayerDao;
import org.cri.redmetrics.model.Event;
import java.util.List;
import java.util.Map;

package org.cri.redmetrics.csv;



/**
 * Created by himmelattack on 12/02/15.
 */
public class EventCsvEntityConverter implements CsvEntityConverter<Event> {
    private PlayerDao playerDao;

    @Inject
    public EventCsvEntityConverter(PlayerDao playerDao) {
        this.playerDao = playerDao;
    }

    @Override
    public void write(CSVWriter csvWriter, List<Event> models) {
        String[] staticColumnNames = {
                "id",
                "serverTime",
                "userTime",
                "gameVersion",
                "playerId",
                "playerBirthdate",
                "playerRegion",
                "playerCountry",
                "playerGender",
                "playerExternalId",
                "playerCustomData",
                "type",
                "coordinates",
                "section",
        };

        CsvHelper.UnpackedCustomData unpackedCustomData = CsvHelper.unpackCustomData(models);

        String[] customDataColumnNames = unpackedCustomData.columnNames.toArray(new String[0]);
        String[] allColumnNames = CsvHelper.concatenateArrays(staticColumnNames, customDataColumnNames);

        csvWriter.writeNext(allColumnNames);

        // Write out rows
        for(int i = 0; i < models.size(); i++) {