export const DELETE_WINDOW_MS = 24 * 60 * 60 * 1000;

export function parseMessageCreatedAt(
  createdAt?: string | null,
  createdAtIso?: string | null
): Date | null {
  const raw = createdAtIso || createdAt;
  if (!raw) return null;
  const d = new Date(String(raw));
  return Number.isNaN(d.getTime()) ? null : d;
}

export function isMessageDeletable(
  createdAt?: string | null,
  createdAtIso?: string | null
): boolean {
  const created = parseMessageCreatedAt(createdAt, createdAtIso);
  if (!created) return false;
  return Date.now() - created.getTime() <= DELETE_WINDOW_MS;
}
