import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { XiaobaoRiskService } from './xiaobao-risk.service';

@Controller('xiaobao-risk')
export class XiaobaoRiskController {
  constructor(private readonly risks: XiaobaoRiskService) {}

  @Get('dirty-count')
  countDirtySummaries() {
    return this.risks.countDirtySummaries();
  }

  @Post(':versionId/enqueue')
  enqueueRefresh(@Param('versionId') versionId: string) {
    return this.risks.markDirtyAndEnqueue(versionId);
  }

  @Post(':versionId/refresh')
  refreshSummary(
    @Param('versionId') versionId: string,
    @Body('now') now?: string,
  ) {
    return this.risks.refreshSummary(versionId, {
      now: now ? new Date(now) : undefined,
    });
  }
}
