/**
 * Order types for the Order Management System
 */

export type OrderStatus = 'draft' | 'confirmed' | 'partially_invoiced' | 'fully_invoiced' | 'cancelled';

export interface OrderLine {
  lineNumber: number;
  productId?: string;
  description: string;
  quantity: number;
  unit?: string;
  unitPrice: number;
  discountPercent: number;
  vatCode: string;
  accountId?: string;
  amountExVat: number;
  amountVat: number;
  amountTotal: number;
  // Invoice tracking
  isInvoiced: boolean;
  invoiceId?: string;
  invoicedAt?: string;
}

export interface Order {
  id: string;
  companyId: string;
  fiscalYearId?: string;
  customerId: string;
  customerName: string;
  customerNumber: string;
  orderNumber: string;
  orderDate?: string;
  expectedDeliveryDate?: string;
  status: OrderStatus;
  amountExVat: number;
  amountVat: number;
  amountTotal: number;
  uninvoicedAmount?: number;
  uninvoicedLineCount?: number;
  currency: string;
  notes?: string;
  reference?: string;
  confirmedAt?: string;
  confirmedBy?: string;
  cancelledAt?: string;
  cancelledReason?: string;
  cancelledBy?: string;
  createdBy: string;
  updatedBy?: string;
  createdAt: string;
  updatedAt: string;
  lines: OrderLine[];
  uninvoicedLines?: OrderLine[];
}

// Status labels in Danish
export const ORDER_STATUS_LABELS: Record<OrderStatus, string> = {
  draft: 'Kladde',
  confirmed: 'Bekræftet',
  partially_invoiced: 'Delvist faktureret',
  fully_invoiced: 'Fuldt faktureret',
  cancelled: 'Annulleret',
};

// Status colors for Ant Design tags
export const ORDER_STATUS_COLORS: Record<OrderStatus, string> = {
  draft: 'default',
  confirmed: 'processing',
  partially_invoiced: 'warning',
  fully_invoiced: 'success',
  cancelled: 'error',
};
