/**
 * 採購單相關常數
 */

import type { PurchaseOrderStatus, PaymentMethod, InvoiceType } from "../types/purchase-order";

// 狀態標籤配置（統一使用灰色線框樣式）
export const STATUS_CONFIG: Record<
  PurchaseOrderStatus,
  { label: string; variant: "default" | "secondary" | "destructive" | "outline" }
> = {
  draft: { label: "草稿", variant: "outline" },
  review_pending: { label: "待審核", variant: "outline" },
  processing: { label: "處理中", variant: "outline" },
  shipping: { label: "運送中", variant: "outline" },
  pending_confirm: { label: "待確認", variant: "outline" },
  completed: { label: "已完成", variant: "outline" },
  rejected: { label: "已退回", variant: "outline" },
};

// 狀態流轉規則
export const STATUS_TRANSITIONS: Record<PurchaseOrderStatus, PurchaseOrderStatus[]> = {
  draft: ["review_pending"], // 草稿 → 送審
  review_pending: ["processing", "rejected"], // 待審核 → 處理中/退回
  processing: ["shipping"], // 處理中 → 運送中
  shipping: ["pending_confirm"], // 運送中 → 待確認
  pending_confirm: ["completed"], // 待確認 → 已完成
  completed: [], // 已完成（終點）
  rejected: ["review_pending"], // 已退回 → 重新送審
};

// 狀態動作按鈕文字（主要動作）
export const STATUS_ACTION_LABELS: Partial<Record<PurchaseOrderStatus, string>> = {
  draft: "送出審核",
  review_pending: "審核",
  processing: "標記為運送中",
  shipping: "標記為待確認",
  pending_confirm: "確認完成",
  rejected: "重新送審",
};

// 付款方式選項
export const PAYMENT_METHODS: Record<PaymentMethod, string> = {
  cash: "現金",
  bank_transfer: "銀行轉帳",
  credit_card: "信用卡",
  check: "支票",
};

// 發票類型選項
export const INVOICE_TYPES: Record<InvoiceType, string> = {
  duplicate: "二聯式",
  triplicate: "三聯式",
  electronic: "電子發票",
};

// 異常原因選項
export const ISSUE_REASONS = [
  { value: "廠商短缺", label: "廠商短缺" },
  { value: "運送損壞", label: "運送損壞" },
  { value: "包裝破損", label: "包裝破損" },
  { value: "品質不符", label: "品質不符" },
  { value: "數量錯誤", label: "數量錯誤" },
  { value: "其他", label: "其他" },
];

// 退回原因選項
export const REJECTION_REASONS = [
  { value: "預算不足", label: "預算不足" },
  { value: "非必要採購", label: "非必要採購" },
  { value: "數量過多", label: "數量過多" },
  { value: "價格過高", label: "價格過高" },
  { value: "資訊不完整", label: "資訊不完整" },
  { value: "其他", label: "其他" },
];

// 價格警示閾值（%）
export const PRICE_ALERT_THRESHOLD = 5;
