import {
  Controller,
  Get,
  Post,
  Query,
  Body,
  UseGuards,
  Param,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard, RolesGuard } from '@/common';
import { Roles } from '@/common/decorators/roles.decorator';
import { ReconciliationService } from '@/modules/shared/finance/reconciliation.service';
import {
  ManualReconciliationDto,
  QueryReconciliationDto,
} from '@/modules/shared/finance/dto/reconciliation.dto';

@ApiTags('对账管理(管理员)')
@Controller('admin/finance/reconciliations')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@ApiBearerAuth()
export class ReconciliationAdminController {
  constructor(private readonly reconciliationService: ReconciliationService) {}

  @Get()
  @ApiOperation({ summary: '查询对账记录' })
  async getReconciliations(@Query() dto: QueryReconciliationDto) {
    return this.reconciliationService.getReconciliations({
      status: dto.status,
      startDate: dto.startDate,
      endDate: dto.endDate,
      page: dto.page,
      pageSize: dto.pageSize,
    });
  }

  @Get(':id')
  @ApiOperation({ summary: '查询对账详情' })
  async getReconciliationDetail(@Param('id') id: number) {
    // TODO: 实现查询对账详情
    return { message: '功能开发中' };
  }

  @Post('manual')
  @ApiOperation({ summary: '手动触发对账' })
  async manualReconciliation(@Body() dto: ManualReconciliationDto) {
    return this.reconciliationService.manualReconciliation(dto.date);
  }
}
