/**
 * 文件职责：财务中心到账查询 API 契约与请求封装。
 */
import { requestClient } from '#/api/request';

/** 到账渠道筛选值。 */
export type FinanceSettlementChannelFilter = 'alipay' | 'all' | 'wechat';

/** 到账查询筛选参数。 */
export interface FinanceSettlementFilterQuery {
  channel?: FinanceSettlementChannelFilter;
  endDate?: string;
  startDate?: string;
  storeId: string;
}

/** 到账查询列表参数。 */
export interface FinanceSettlementListQuery extends FinanceSettlementFilterQuery {
  page: number;
  pageSize: number;
}

/** 到账统计结果。 */
export interface FinanceSettlementStatsDto {
  currentMonthArrivedAmount: number;
  currentMonthTransactionCount: number;
  todayArrivedAmount: number;
  yesterdayArrivedAmount: number;
}

/** 到账账户信息。 */
export interface FinanceSettlementAccountDto {
  alipayPidMasked: string;
  bankAccountName: string;
  bankAccountNoMasked: string;
  bankName: string;
  settlementPeriodText: string;
  wechatMerchantNoMasked: string;
}

/** 到账列表行。 */
export interface FinanceSettlementListItemDto {
  arrivedAmount: number;
  arrivedDate: string;
  channel: 'alipay' | 'wechat';
  channelText: string;
  transactionCount: number;
}

/** 到账列表结果。 */
export interface FinanceSettlementListResultDto {
  items: FinanceSettlementListItemDto[];
  page: number;
  pageSize: number;
  total: number;
}

/** 到账明细查询参数。 */
export interface FinanceSettlementDetailQuery {
  arrivedDate: string;
  channel: 'alipay' | 'wechat';
  storeId: string;
}

/** 到账明细行。 */
export interface FinanceSettlementDetailItemDto {
  amount: number;
  orderNo: string;
  paidAt: string;
}

/** 到账明细结果。 */
export interface FinanceSettlementDetailResultDto {
  items: FinanceSettlementDetailItemDto[];
}

/** 到账导出结果。 */
export interface FinanceSettlementExportDto {
  fileContentBase64: string;
  fileName: string;
  totalCount: number;
}

/** 查询到账统计。 */
export async function getFinanceSettlementStatsApi(params: {
  storeId: string;
}) {
  return requestClient.get<FinanceSettlementStatsDto>(
    '/finance/settlement/stats',
    {
      params,
    },
  );
}

/** 查询到账账户信息。 */
export async function getFinanceSettlementAccountApi() {
  return requestClient.get<FinanceSettlementAccountDto>(
    '/finance/settlement/account',
  );
}

/** 查询到账列表。 */
export async function getFinanceSettlementListApi(
  params: FinanceSettlementListQuery,
) {
  return requestClient.get<FinanceSettlementListResultDto>(
    '/finance/settlement/list',
    {
      params,
    },
  );
}

/** 查询到账明细。 */
export async function getFinanceSettlementDetailApi(
  params: FinanceSettlementDetailQuery,
) {
  return requestClient.get<FinanceSettlementDetailResultDto>(
    '/finance/settlement/detail',
    {
      params,
    },
  );
}

/** 导出到账汇总 CSV。 */
export async function exportFinanceSettlementCsvApi(
  params: FinanceSettlementFilterQuery,
) {
  return requestClient.get<FinanceSettlementExportDto>(
    '/finance/settlement/export',
    {
      params,
    },
  );
}
