import type { LeaseDetailStatus } from './types';

/** 宽表列定义（对齐 Excel「租赁车辆收入明细表」） */
export interface LeaseTableColumn {
  key: string;
  title: string;
  money?: boolean;
  date?: boolean;
  sticky?: 'left' | 'right';
  className?: string;
  annotationId?: string;
  headerTip?: string;
  sortable?: boolean;
  defaultWidth?: number;
  render?:
    | 'stack-dept' | 'stack-plate' | 'stack-customer' | 'status' | 'deposit'
    | 'asset-owner' | 'signing-company'
    | 'monthly-income' | 'maintenance-income' | 'insurance-surcharge' | 'ops-fee-income' | 'other-income'
    | 'received-amount' | 'invoice-date' | 'vehicle-standard-cost' | 'vehicle-actual-cost'
    | 'insurance-readonly' | 'hydrogen-fee' | 'ops-fee-cost'
    | 'brokerage-fee' | 'other-cost' | 'gps-mileage'
    | 'deduction-detail' | 'remark-text' | 'text';
}

export const LEASE_TABLE_COLUMNS: LeaseTableColumn[] = [
  { key: '_index', title: '序号', sticky: 'left', className: 'tabular-nums' },
  { key: 'status', title: '状态', render: 'status', annotationId: 'lbl-col-status' },
  { key: 'maintainerName', title: '维护人' },
  { key: 'year', title: '年份', className: 'tabular-nums' },
  { key: 'month', title: '月份', className: 'tabular-nums' },
  { key: 'dept', title: '业务部门', render: 'stack-dept', annotationId: 'lbl-col-dept' },
  { key: 'paymentDate', title: '付款日期', date: true },
  { key: 'plateNo', title: '车牌号码', render: 'stack-plate', annotationId: 'lbl-col-plate' },
  { key: 'customerName', title: '客户名称', render: 'stack-customer', annotationId: 'lbl-col-customer' },
  { key: 'valueAddedService', title: '增值服务' },
  { key: 'exemptionPolicy', title: '享免政策' },
  { key: 'pickupDate', title: '提车日期', date: true, annotationId: 'lbl-col-pickup-date' },
  { key: 'contractStartDate', title: '合同生效日期', date: true },
  { key: 'contractEndDate', title: '合同到期日期', date: true },
  { key: 'periodStartDate', title: '起始日期', date: true },
  { key: 'returnDate', title: '退车日期', date: true },
  { key: 'avgDays', title: '平均天数', className: 'tabular-nums' },
  { key: 'deposit', title: '保证金', render: 'deposit', annotationId: 'lbl-col-deposit' },
  { key: 'contractRent', title: '合同标的租金', money: true, annotationId: 'lbl-col-contract-rent' },
  { key: 'receivableTotal', title: '应收合计', money: true },
  { key: 'receivableRent', title: '应收租金', money: true, annotationId: 'lbl-col-receivable-rent' },
  { key: 'monthlyIncome', title: '月度收入', money: true, render: 'monthly-income', annotationId: 'lbl-col-monthly-income' },
  { key: 'monthlyRent', title: '月度租金', money: true, annotationId: 'lbl-col-monthly-rent' },
  { key: 'maintenanceIncome', title: '维保包干收入', money: true, render: 'maintenance-income', annotationId: 'lbl-col-maintenance-income' },
  { key: 'insuranceSurcharge', title: '保险上浮费', money: true, render: 'insurance-surcharge', annotationId: 'lbl-col-insurance-surcharge' },
  { key: 'opsFeeIncome', title: '运维费', money: true, className: 'ldb-col-ops-income', render: 'ops-fee-income', annotationId: 'lbl-col-ops-income' },
  { key: 'otherIncome', title: '其他收入', money: true, render: 'other-income', annotationId: 'lbl-col-other-income' },
  { key: 'mileageDeduction', title: '里程减免金额', money: true },
  { key: 'otherDeduction', title: '其他减免金额', money: true },
  { key: 'receivedAmount', title: '实收金额', money: true, render: 'received-amount', annotationId: 'lbl-col-received-amount' },
  { key: 'unreceived', title: '未收金额', money: true, annotationId: 'lbl-col-unreceived' },
  { key: 'invoiceDate', title: '开票日期', date: true, render: 'invoice-date', annotationId: 'lbl-col-invoice-date' },
  { key: 'actualPaymentDate', title: '实际付款日期', date: true, annotationId: 'lbl-col-actual-payment' },
  { key: 'paymentMethod', title: '付款方式', annotationId: 'lbl-col-payment-method' },
  { key: 'vehicleStandardCost', title: '车辆标准成本', money: true, render: 'vehicle-standard-cost', annotationId: 'lbl-col-vehicle-standard-cost' },
  { key: 'vehicleActualCost', title: '车辆实际成本', money: true, render: 'vehicle-actual-cost', annotationId: 'lbl-col-vehicle-actual-cost' },
  { key: 'insuranceFee', title: '保险费', money: true, render: 'insurance-readonly', annotationId: 'lbl-col-insurance-fee' },
  {
    key: 'hydrogenFee',
    title: '氢费',
    money: true,
    render: 'hydrogen-fee',
    annotationId: 'lbl-col-hydrogen-fee',
    headerTip: '仅显示签订合同时氢费承担方式为「我司承担」的氢费在该账单期内的总和，取自车辆氢费明细所有状态的数据（包含未对账和已对账）',
  },
  { key: 'opsFeeCost', title: '运维费', money: true, className: 'ldb-col-ops-cost', render: 'ops-fee-cost', annotationId: 'lbl-col-ops-cost' },
  { key: 'brokerageFee', title: '居间费', money: true, render: 'brokerage-fee', annotationId: 'lbl-col-brokerage-fee' },
  { key: 'otherCost', title: '其他', money: true, render: 'other-cost', annotationId: 'lbl-col-other-cost' },
  { key: 'totalCost', title: '总成本', money: true },
  { key: 'profitLoss', title: '盈亏', money: true },
  { key: 'gpsMileage', title: 'GPS里程', render: 'gps-mileage', annotationId: 'lbl-col-gps-mileage' },
  { key: 'otherDeductionDetail', title: '其他减免金额明细内容', className: 'ldb-col-remark', render: 'deduction-detail', annotationId: 'lbl-col-deduction-detail' },
  { key: 'assetOwner', title: '资产归属', render: 'asset-owner', annotationId: 'lbl-col-asset-ownership' },
  { key: 'signingCompany', title: '签约公司', className: 'ldb-col-name', render: 'signing-company', annotationId: 'lbl-col-signing-company' },
  { key: 'remark', title: '备注', className: 'ldb-col-remark', render: 'remark-text', annotationId: 'lbl-col-remark' },
];

export const STATUS_CLASS: Record<LeaseDetailStatus, string> = {
  草稿: 'ldb-status--draft',
  已确认: 'ldb-status--confirmed',
  部分收款: 'ldb-status--partial',
  已收款: 'ldb-status--paid',
};
