// Common utility functions that can be used by both admin and user APIs

export function formatDate(date: Date): string {
  return date.toISOString();
}

export function generateCode(prefix: string, length: number = 6): string {
  const timestamp = Date.now().toString().slice(-length);
  const random = Math.random().toString(36).substring(2, 8).toUpperCase();
  return `${prefix}${timestamp}${random}`;
}

export function calculateDiscount(amount: number, percent: number, maxDiscount?: number): number {
  let discount = (amount * percent) / 100;
  if (maxDiscount && discount > maxDiscount) {
    discount = maxDiscount;
  }
  return discount;
}
