// Purchase Order Status Codes
export enum PurchaseOrderStatus {
  Canceled = 0,
  Created = 1,
  ElectronicallyReadySend = 10,
  Ordered = 11,
  Preordered = 12,
  ElectronicallySent = 13,
  ReceivingStarted = 15,
  Done = 50
}

// Receiving Status Codes
export enum ReceivingStatus {
  Canceled = 0,
  Created = 1,
  PartialReceived = 30,
  FullReceived = 40,
  Paid = 50
}

// Status Code Display Names
export const PurchaseOrderStatusLabels: Record<PurchaseOrderStatus, string> = {
  [PurchaseOrderStatus.Canceled]: 'Canceled',
  [PurchaseOrderStatus.Created]: 'Created',
  [PurchaseOrderStatus.ElectronicallyReadySend]: 'Ready to Send',
  [PurchaseOrderStatus.Ordered]: 'Ordered',
  [PurchaseOrderStatus.Preordered]: 'Preordered',
  [PurchaseOrderStatus.ElectronicallySent]: 'Sent',
  [PurchaseOrderStatus.ReceivingStarted]: 'Receiving Started',
  [PurchaseOrderStatus.Done]: 'Done'
};

export const ReceivingStatusLabels: Record<ReceivingStatus, string> = {
  [ReceivingStatus.Canceled]: 'Canceled',
  [ReceivingStatus.Created]: 'Created',
  [ReceivingStatus.PartialReceived]: 'Partially Received',
  [ReceivingStatus.FullReceived]: 'Fully Received',
  [ReceivingStatus.Paid]: 'Paid'
};

// Helper functions
export function getPurchaseOrderStatusLabel(status: number): string {
  return PurchaseOrderStatusLabels[status as PurchaseOrderStatus] || 'Unknown';
}

export function getReceivingStatusLabel(status: number): string {
  return ReceivingStatusLabels[status as ReceivingStatus] || 'Unknown';
}

// Status checks
export function isReceivingComplete(status: number): boolean {
  return status >= ReceivingStatus.PartialReceived;
}

export function isPurchaseOrderComplete(status: number): boolean {
  return status === PurchaseOrderStatus.Done;
}

export function isPurchaseOrderCanceled(status: number): boolean {
  return status === PurchaseOrderStatus.Canceled;
}

export function isReceivingCanceled(status: number): boolean {
  return status === ReceivingStatus.Canceled;
}

// Badge variants for different statuses
export function getPurchaseOrderStatusVariant(status: number): 'default' | 'secondary' | 'destructive' | 'outline' {
  if (isPurchaseOrderCanceled(status)) return 'destructive';
  if (isPurchaseOrderComplete(status)) return 'default';
  if (status >= PurchaseOrderStatus.ElectronicallyReadySend) return 'secondary';
  return 'outline';
}

export function getReceivingStatusVariant(status: number): 'default' | 'secondary' | 'destructive' | 'outline' {
  if (isReceivingCanceled(status)) return 'destructive';
  if (status === ReceivingStatus.Paid || status === ReceivingStatus.FullReceived) return 'default';
  if (status >= ReceivingStatus.PartialReceived) return 'secondary';
  return 'outline';
} 