import { ApiProperty } from '@nestjs/swagger';

export class LedgerEntryResponseDTO {
  @ApiProperty({ description: '流水ID' })
  id: string;

  @ApiProperty({ description: '流水类型' })
  entryType: string;

  @ApiProperty({ description: '金额 (正数入账, 负数支出)' })
  amount: number;

  @ApiProperty({ description: '资产类型' })
  assetType: string;

  @ApiProperty({ description: '操作后余额', nullable: true })
  balanceAfter: number | null;

  @ApiProperty({ description: '关联订单ID', nullable: true })
  refOrderId: string | null;

  @ApiProperty({ description: '关联交易哈希', nullable: true })
  refTxHash: string | null;

  @ApiProperty({ description: '备注', nullable: true })
  memo: string | null;

  @ApiProperty({ description: '权益分配类型 (SHARE_RIGHT, PROVINCE_AREA_RIGHT, CITY_AREA_RIGHT, COMMUNITY_RIGHT 等)', nullable: true })
  allocationType: string | null;

  @ApiProperty({ description: '创建时间' })
  createdAt: string;
}

export class PaginatedLedgerResponseDTO {
  @ApiProperty({ type: [LedgerEntryResponseDTO], description: '流水列表' })
  data: LedgerEntryResponseDTO[];

  @ApiProperty({ description: '总记录数' })
  total: number;

  @ApiProperty({ description: '当前页码' })
  page: number;

  @ApiProperty({ description: '每页数量' })
  pageSize: number;

  @ApiProperty({ description: '总页数' })
  totalPages: number;
}

// ============ 统计相关 DTO ============

export class EntryTypeSummaryDTO {
  @ApiProperty({ description: '流水类型' })
  entryType: string;

  @ApiProperty({ description: '流水类型中文名' })
  entryTypeName: string;

  @ApiProperty({ description: '总金额' })
  totalAmount: number;

  @ApiProperty({ description: '笔数' })
  count: number;
}

export class LedgerStatisticsResponseDTO {
  @ApiProperty({ description: '总收入' })
  totalIncome: number;

  @ApiProperty({ description: '总支出' })
  totalExpense: number;

  @ApiProperty({ description: '净收益' })
  netAmount: number;

  @ApiProperty({ description: '总笔数' })
  totalCount: number;

  @ApiProperty({ type: [EntryTypeSummaryDTO], description: '按类型汇总' })
  byEntryType: EntryTypeSummaryDTO[];

  @ApiProperty({ description: '统计时间范围开始' })
  startDate: string;

  @ApiProperty({ description: '统计时间范围结束' })
  endDate: string;
}

export class DailyTrendItemDTO {
  @ApiProperty({ description: '日期' })
  date: string;

  @ApiProperty({ description: '收入' })
  income: number;

  @ApiProperty({ description: '支出' })
  expense: number;

  @ApiProperty({ description: '净收益' })
  net: number;

  @ApiProperty({ description: '笔数' })
  count: number;
}

export class LedgerTrendResponseDTO {
  @ApiProperty({ type: [DailyTrendItemDTO], description: '每日趋势' })
  dailyTrend: DailyTrendItemDTO[];

  @ApiProperty({ description: '统计天数' })
  days: number;

  @ApiProperty({ description: '期间总收入' })
  periodIncome: number;

  @ApiProperty({ description: '期间总支出' })
  periodExpense: number;

  @ApiProperty({ description: '期间净收益' })
  periodNet: number;
}
