package de.assecutor.votianlt.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * Utility class for consistent date and time formatting across the application.
 * All dates and times are formatted in German format: "TT.MM.JJJJ, HH:MM Uhr"
 */
public class DateTimeFormatUtil {

    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy, HH:mm 'Uhr'");
    private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy");
    private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm 'Uhr'");

    private DateTimeFormatUtil() {
        // Utility class, no instantiation
    }

    /**
     * Formats a LocalDateTime to German format: "TT.MM.JJJJ, HH:MM Uhr"
     *
     * @param dateTime
     *            the LocalDateTime to format
     * @return formatted string or empty string if dateTime is null
     */
    public static String formatDateTime(LocalDateTime dateTime) {
        if (dateTime == null) {
            return "";
        }
        return dateTime.format(DATE_TIME_FORMATTER);
    }

    /**
     * Formats a LocalDate to German format: "TT.MM.JJJJ"
     *
     * @param date
     *            the LocalDate to format
     * @return formatted string or empty string if date is null
     */
    public static String formatDate(LocalDate date) {
        if (date == null) {
            return "";
        }
        return date.format(DATE_FORMATTER);
    }

    /**
     * Formats only the time part: "HH:MM Uhr"
     *
     * @param dateTime
     *            the LocalDateTime to format
     * @return formatted time string or empty string if dateTime is null
     */
    public static String formatTime(LocalDateTime dateTime) {
        if (dateTime == null) {
            return "";
        }
        return dateTime.format(TIME_FORMATTER);
    }

    /**
     * Formats a LocalTime to German format: "HH:MM Uhr"
     *
     * @param time
     *            the LocalTime to format
     * @return formatted time string or empty string if time is null
     */
    public static String formatTime(LocalTime time) {
        if (time == null) {
            return "";
        }
        return time.format(TIME_FORMATTER);
    }

    /**
     * Returns the date time formatter for direct use
     *
     * @return the DateTimeFormatter instance
     */
    public static DateTimeFormatter getDateTimeFormatter() {
        return DATE_TIME_FORMATTER;
    }

    /**
     * Returns the date formatter for direct use
     *
     * @return the DateTimeFormatter instance
     */
    public static DateTimeFormatter getDateFormatter() {
        return DATE_FORMATTER;
    }
}
