import { get, post } from '@/utils/request';

/**
 * 商家财务API
 */
export const financeApi = {
  /**
   * 获取钱包信息
   */
  getWallet: () => get('/api/merchant/finance/wallet'),

  /**
   * 获取交易流水
   */
  getTransactions: (params?: any) => get('/api/merchant/finance/transactions', params),

  /**
   * 获取结算记录
   */
  getSettlements: (params?: any) => get('/api/merchant/finance/settlements', params),

  /**
   * 获取结算详情
   */
  getSettlementDetail: (id: number) => get(`/seller/finance/settlements/${id}`),

  /**
   * 获取结算明细
   */
  getSettlementItems: (id: number, params?: any) =>
    get(`/seller/finance/settlements/${id}/items`, params),

  /**
   * 申请提现
   */
  withdraw: (data: {
    amount: number;
    accountType: 'bank' | 'alipay' | 'wechat';
    accountName: string;
    accountNumber: string;
    bankName?: string;
  }) => post('/api/merchant/finance/withdrawals', data),

  /**
   * 获取提现记录
   */
  getWithdrawals: (params?: any) => get('/api/merchant/finance/withdrawals', params),

  /**
   * 获取提现详情
   */
  getWithdrawalDetail: (id: number) => get(`/seller/finance/withdrawals/${id}`),
};

/**
 * 商家统计API
 */
export const statisticsApi = {
  /**
   * 获取数据概览
   */
  getOverview: () => get('/api/merchant/statistics/overview'),

  /**
   * 获取收入趋势
   */
  getIncomeTrend: (type: 'day' | 'week' | 'month' = 'day') =>
    get('/api/merchant/statistics/income-trend', { type }),
};
