/**
 * Common date formatting utility for backend modules
 */
export function formatDateTime(date: string | Date | number, format: 'full' | 'date' | 'time' = 'full') {
    const d = new Date(date);
    
    // Check for invalid date
    if (isNaN(d.getTime())) return 'Invalid Date';

    const options: Intl.DateTimeFormatOptions = {
        day: '2-digit',
        month: 'short',
        year: 'numeric',
    };

    if (format === 'full' || format === 'time') {
        options.hour = '2-digit';
        options.minute = '2-digit';
        options.hour12 = true;
    }

    if (format === 'time') {
        return d.toLocaleTimeString('en-IN', { hour: '2-digit', minute: '2-digit', hour12: true });
    }

    return d.toLocaleDateString('en-IN', options);
}

/**
 * Returns current timestamp in YYYY-MM-DD HH:mm:ss format
 */
export function getCurrentTimestamp() {
    return new Date().toISOString().replace('T', ' ').substring(0, 19);
}
