import type {
  FinanceTransactionFilterState,
  FinanceTransactionPageSummaryState,
  OptionItem,
  QuickRangeOption,
} from '../../types';

/**
 * 文件职责：交易流水页面常量与默认状态定义。
 */
import type {
  FinanceTransactionChannelFilter,
  FinanceTransactionPaymentFilter,
  FinanceTransactionStatsDto,
  FinanceTransactionTypeFilter,
} from '#/api/finance';

import { getTodayDateString } from './helpers';

/** 交易流水查看权限。 */
export const FINANCE_TRANSACTION_VIEW_PERMISSION =
  'tenant:finance:transaction:view';

/** 交易流水导出权限。 */
export const FINANCE_TRANSACTION_EXPORT_PERMISSION =
  'tenant:finance:transaction:export';

/** 交易类型筛选项。 */
export const TRANSACTION_TYPE_OPTIONS: OptionItem[] = [
  { label: '全部类型', value: 'all' },
  { label: '收入', value: 'income' },
  { label: '退款', value: 'refund' },
  { label: '储值充值', value: 'stored_card_recharge' },
  { label: '积分抵扣', value: 'point_redeem' },
];

/** 交易渠道筛选项。 */
export const TRANSACTION_CHANNEL_OPTIONS: OptionItem[] = [
  { label: '全部渠道', value: 'all' },
  { label: '外卖', value: 'delivery' },
  { label: '自提', value: 'pickup' },
  { label: '堂食', value: 'dine_in' },
];

/** 支付方式筛选项。 */
export const TRANSACTION_PAYMENT_OPTIONS: OptionItem[] = [
  { label: '全部支付方式', value: 'all' },
  { label: '微信', value: 'wechat' },
  { label: '支付宝', value: 'alipay' },
  { label: '现金', value: 'cash' },
  { label: '刷卡', value: 'card' },
  { label: '储值余额', value: 'balance' },
];

/** 快捷日期选项。 */
export const QUICK_RANGE_OPTIONS: QuickRangeOption[] = [
  { label: '今天', value: 'today' },
  { label: '昨天', value: 'yesterday' },
  { label: '近7天', value: '7d' },
  { label: '近30天', value: '30d' },
  { label: '本月', value: 'month' },
];

/** 默认筛选状态。 */
export function createDefaultFilters(): FinanceTransactionFilterState {
  const today = getTodayDateString();
  return {
    type: 'all' as FinanceTransactionTypeFilter,
    channel: 'all' as FinanceTransactionChannelFilter,
    paymentMethod: 'all' as FinanceTransactionPaymentFilter,
    keyword: '',
    startDate: today,
    endDate: today,
    quickRange: 'today',
  };
}

/** 默认统计数据。 */
export const DEFAULT_STATS: FinanceTransactionStatsDto = {
  totalIncome: 0,
  totalRefund: 0,
  totalCount: 0,
};

/** 默认本页汇总数据。 */
export const DEFAULT_PAGE_SUMMARY: FinanceTransactionPageSummaryState = {
  pageIncomeAmount: 0,
  pageRefundAmount: 0,
};
