package fr.epicanard.globalmarketchest.utils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Calendar;

import lombok.experimental.UtilityClass;

/**
 * Utiity Class for database actions
 */
@UtilityClass
public class DatabaseUtils {
  /**
   * Get current timestamp
   * 
   * @return Timestamp
   */
  public Timestamp getTimestamp() {
    return new Timestamp(System.currentTimeMillis());
  }

  /**
   * Add days to a spécific timestamp
   * 
   * @param ts    Timestamp used
   * @param days  Nummber of days to add
   * @return Return the new timestamp
   */
  public Timestamp addDays(Timestamp ts, int days) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(ts);
    cal.add(Calendar.DAY_OF_WEEK, days);
    return new Timestamp(cal.getTime().getTime());
  }

  /**
   * Get an id from resultSet
   * 
   * @param res ResultSet
   * @return Return the id or -1
   */
  public Integer getId(ResultSet res) {
    Integer id = -1;
    try {
      res.next();
      id = res.getInt(1);
    } catch(SQLException e) { e.printStackTrace(); }
    return id;
  }

  public String joinRepeat(String str, String sep, int repeat) {
    String ret = "";
    for (int i = 0; i < repeat; i++) {
      ret += str;
      if (i != repeat - 1)
        ret += sep;
    }
    return ret;
  }
}

@@ -151,16 +151,213 @@
 lendar;%0A
+import java.util.List;%0Aimport java.util.function.BiConsumer;%0Aimport java.util.stream.Collectors;%0A%0Aimport org.bukkit.inventory.ItemStack;%0A%0Aimport fr.epicanard.globalmarketchest.auctions.AuctionInfo;
 %0Aimport 
@@ -1534,11 +1534,369 @@
 ret;%0A  %7D
+%0A%0A  public List%3CItemStack%3E toItemStacks(List%3CAuctionInfo%3E auctions, BiConsumer%3CItemStack, AuctionInfo%3E adding) %7B%0A    return auctions.stream().map(auction -%3E %7B%0A      ItemStack item = ItemStackUtils.getItemStack(auction.getItemStack());%0A      if (adding != null)%0A        adding.accept(item, auction);%0A      return item;%0A    %7D).collect(Collectors.toList());%0A  %7D
 %0A%7D%0A

Add convertor from auctions to itemstack