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

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" },
    pending: { label: "簽核中", variant: "outline" },
    approved: { label: "已核准", variant: "default" },
    partial: { label: "部分收貨", variant: "secondary" },
    completed: { label: "全數收貨", variant: "outline" },
    closed: { label: "已結案", variant: "outline" },
    cancelled: { label: "已作廢", variant: "destructive" },
};

// 供下單/編輯頁面使用的手動狀態選項 (排除系統自動狀態)
export const MANUAL_STATUS_OPTIONS = [
    { value: 'draft', label: '草稿' },
    { value: 'pending', label: '送審中' },
    { value: 'approved', label: '已核准' },
    { value: 'cancelled', label: '已作廢' },
];

export const STATUS_OPTIONS = Object.entries(STATUS_CONFIG).map(([value, config]) => ({
    value,
    label: (config as any).label,
}));

// 付款方式選項
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 REJECTION_REASONS = [
    { value: "預算不足", label: "預算不足" },
    { value: "非必要採購", label: "非必要採購" },
    { value: "數量過多", label: "數量過多" },
    { value: "價格過高", label: "價格過高" },
    { value: "資訊不完整", label: "資訊不完整" },
    { value: "其他", label: "其他" },
];

/**
 * 價格警示閾值（百分比）
 * 當單價比上次採購價高出此百分比時，顯示警示
 */
export const PRICE_ALERT_THRESHOLD = 5;
