import { Controller, Get, Param, Query } from '@nestjs/common';
import {
  ApiTags,
  ApiOperation,
  ApiBearerAuth,
  ApiParam,
  ApiQuery,
} from '@nestjs/swagger';
import { PendingContributionsService } from '../../application/services/pending-contributions.service';

@ApiTags('Pending Contributions')
@ApiBearerAuth()
@Controller('pending-contributions')
export class PendingContributionsController {
  constructor(
    private readonly pendingContributionsService: PendingContributionsService,
  ) {}

  @Get()
  @ApiOperation({ summary: '获取待解锁算力列表' })
  @ApiQuery({ name: 'page', required: false, type: Number })
  @ApiQuery({ name: 'pageSize', required: false, type: Number })
  @ApiQuery({
    name: 'contributionType',
    required: false,
    type: String,
    description: '算力类型筛选',
  })
  async getPendingContributions(
    @Query('page') page?: number,
    @Query('pageSize') pageSize?: number,
    @Query('contributionType') contributionType?: string,
  ) {
    return this.pendingContributionsService.getPendingContributions(
      page ?? 1,
      pageSize ?? 20,
      contributionType,
    );
  }

  @Get('summary')
  @ApiOperation({ summary: '获取待解锁算力汇总统计' })
  async getPendingContributionsSummary() {
    return this.pendingContributionsService.getPendingContributionsSummary();
  }

  @Get('mining-records')
  @ApiOperation({ summary: '获取所有待解锁算力的挖矿记录' })
  @ApiQuery({ name: 'page', required: false, type: Number })
  @ApiQuery({ name: 'pageSize', required: false, type: Number })
  async getAllPendingMiningRecords(
    @Query('page') page?: number,
    @Query('pageSize') pageSize?: number,
  ) {
    return this.pendingContributionsService.getAllPendingMiningRecords(
      page ?? 1,
      pageSize ?? 20,
    );
  }

  @Get(':id/records')
  @ApiOperation({ summary: '获取某条待解锁算力的挖矿记录' })
  @ApiParam({ name: 'id', type: String, description: '待解锁算力ID' })
  @ApiQuery({ name: 'page', required: false, type: Number })
  @ApiQuery({ name: 'pageSize', required: false, type: Number })
  async getPendingContributionMiningRecords(
    @Param('id') id: string,
    @Query('page') page?: number,
    @Query('pageSize') pageSize?: number,
  ) {
    return this.pendingContributionsService.getPendingContributionMiningRecords(
      id,
      page ?? 1,
      pageSize ?? 20,
    );
  }
}
