/**
 * EAMCO Office Frontend Status Constants
 *
 * This file contains all status code constants used throughout the frontend
 * to eliminate magic numbers and improve code maintainability.
 */

export const DELIVERY_STATUS = {
  WAITING: 0,
  CANCELLED: 1,
  OUT_FOR_DELIVERY: 2,
  TOMORROW: 3,
  PARTIAL_DELIVERY: 4,
  ISSUE: 5,
  UNKNOWN: 6,
  PENDING_PAYMENT: 9,
  FINALIZED: 10,
  DELIVERED: 11, // New: Replaces previous use of 1 for delivered
} as const;

export const PAYMENT_STATUS = {
  UNPAID: 0,
  PRE_AUTHORIZED: 1,
  PROCESSING: 2,
  PAID: 3,
  FAILED: 4,
} as const;

export const AUTO_STATUS = {
  DEFAULT: 0,
  WILL_CALL: 1,
  READY_FOR_FINALIZATION: 3,
} as const;

export const TRANSACTION_STATUS = {
  APPROVED: 0,
  DECLINED: 1,
} as const;

export const CUSTOMER_AUTOMATIC_STATUS = {
  WILL_CALL: 0,
  AUTOMATIC: 1,
} as const;

// Helper functions for type-safe status access
export type DeliveryStatusType = typeof DELIVERY_STATUS[keyof typeof DELIVERY_STATUS];
export type PaymentStatusType = typeof PAYMENT_STATUS[keyof typeof PAYMENT_STATUS];
export type AutoStatusType = typeof AUTO_STATUS[keyof typeof AUTO_STATUS];
export type TransactionStatusType = typeof TRANSACTION_STATUS[keyof typeof TRANSACTION_STATUS];
export type CustomerAutomaticStatus = typeof CUSTOMER_AUTOMATIC_STATUS[keyof typeof CUSTOMER_AUTOMATIC_STATUS];

// Utility functions for status display
export function getDeliveryStatusLabel(status: DeliveryStatusType): string {
  switch (status) {
    case DELIVERY_STATUS.WAITING: return 'Waiting';
    case DELIVERY_STATUS.CANCELLED: return 'Cancelled';
    case DELIVERY_STATUS.OUT_FOR_DELIVERY: return 'Out for Delivery';
    case DELIVERY_STATUS.TOMORROW: return 'Tomorrow';
    case DELIVERY_STATUS.PARTIAL_DELIVERY: return 'Partial Delivery';
    case DELIVERY_STATUS.ISSUE: return 'Issue';
    case DELIVERY_STATUS.UNKNOWN: return 'Unknown';
    case DELIVERY_STATUS.PENDING_PAYMENT: return 'Pending Payment';
    case DELIVERY_STATUS.FINALIZED: return 'Finalized';
    case DELIVERY_STATUS.DELIVERED: return 'Delivered';
    default: return 'N/A';
  }
}

export function getPaymentStatusLabel(status: PaymentStatusType): string {
  switch (status) {
    case PAYMENT_STATUS.UNPAID: return 'Unpaid';
    case PAYMENT_STATUS.PRE_AUTHORIZED: return 'Pre-authorized';
    case PAYMENT_STATUS.PROCESSING: return 'Processing';
    case PAYMENT_STATUS.PAID: return 'Paid';
    case PAYMENT_STATUS.FAILED: return 'Failed';
    default: return 'Unknown';
  }
}

export function getAutoStatusLabel(status: AutoStatusType): string {
  switch (status) {
    case AUTO_STATUS.DEFAULT: return 'Default';
    case AUTO_STATUS.WILL_CALL: return 'Will Call';
    case AUTO_STATUS.READY_FOR_FINALIZATION: return 'Ready for Finalization';
    default: return 'Unknown';
  }
}

export function getTransactionStatusLabel(status: TransactionStatusType): string {
  switch (status) {
    case TRANSACTION_STATUS.APPROVED: return 'Approved';
    case TRANSACTION_STATUS.DECLINED: return 'Declined';
    default: return 'Unknown';
  }
}