package ru.micord.ervu_dashboard.util;

import java.sql.Timestamp;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public final class DateUtils {
  private static final DateTimeFormatter DATE_FORMATTER_RU = DateTimeFormatter.ofPattern(
      "d MMMM yyyy", new Locale("ru", "RU")
  );

  private DateUtils() {}

  public static String formatTimestampWithClientZone(Timestamp timestamp, String clientTimeZone) {
    if (timestamp == null) {
      throw new IllegalArgumentException("Timestamp parameter is required");
    }

    ZoneId zoneId;
    try {
      zoneId = ZoneId.of(clientTimeZone);
    }
    catch (Exception e) {
      zoneId = ZoneId.systemDefault();
    }
    return timestamp.toInstant()
        .atZone(zoneId)
        .format(DATE_FORMATTER_RU);
  }
}
