package de.htwsaar.webshop.util;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;

/**
 * Helper Class for Unix-Millis related Things
 */
public class TimeUtil {

    /**
     * Amount millis representing one minute
     */
    public static final long MILLIS_TO_MINUTE = 60 * 1000;

    /**
     * Amount millis representing one hour
     */
    public static final long MILLIS_TO_HOUR = MILLIS_TO_MINUTE * 60;

    /**
     * Amount millis representing one day
     */
    private static final long MILLIS_TO_DAY = MILLIS_TO_HOUR * 24;

    /**
     * Amount millis representing one week
     */
    public static final long MILLIS_TO_WEEK = MILLIS_TO_DAY * 7;

    /**
     * Amount millis in the first second of 2025
     */
    public static final long VALID_MIN_MILLIS_TIMESTAMP = 1735686000000L;


    /**
     * Now in X days, represented as Unix Millis
     *
     * @param days how many days to add
     * @return the calculated Unix-Millis
     */
    public static long nowPlusDays(long days) {
        return System.currentTimeMillis() + (days * MILLIS_TO_DAY);
    }

    public static long nowMonthsAgo(long months) {
        return LocalDateTime.now().minusMonths(months).atZone(ZoneId.systemDefault()).toEpochSecond();
    }

    public static long monthLength(long epoch) {
        return LocalDateTime.ofEpochSecond(epoch, 0, ZoneOffset.UTC).getMonth().length(false) * MILLIS_TO_DAY;
    }
}
