import { Controller, Get, Post, Param, Body, Query, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiParam, ApiSecurity } from '@nestjs/swagger';
import { ApiKeyGuard } from '../../common/guards/api-key.guard';
import { MtlsGuard } from '../../common/guards/mtls.guard';
import { RequireApiTier } from '../../common/decorators/api-tier.decorator';
import { RegulatoryService } from './regulatory.service';

@ApiTags('regulatory')
@ApiSecurity('api-key')
@Controller('v1/regulatory')
@UseGuards(ApiKeyGuard, MtlsGuard)
export class RegulatoryController {
  constructor(private readonly regulatoryService: RegulatoryService) {}

  @Get('address/:addr/graph')
  @RequireApiTier('regulatory')
  @ApiOperation({ summary: '地址关联图谱（资金流向分析）' })
  @ApiParam({ name: 'addr', description: '目标地址' })
  getAddressGraph(@Param('addr') addr: string) {
    return this.regulatoryService.getAddressGraph(addr);
  }

  @Get('travel-rule/records')
  @RequireApiTier('regulatory')
  @ApiOperation({ summary: 'Travel Rule 记录查询' })
  getTravelRuleRecords(@Query('from') from?: string, @Query('to') to?: string) {
    return this.regulatoryService.getTravelRuleRecords(from, to);
  }

  @Get('suspicious')
  @RequireApiTier('regulatory')
  @ApiOperation({ summary: '可疑交易列表（AI标记 + 规则触发）' })
  getSuspiciousTransactions() {
    return this.regulatoryService.getSuspiciousTransactions();
  }

  @Post('freeze')
  @RequireApiTier('regulatory')
  @ApiOperation({ summary: '请求冻结地址（触发 Governance 多签流程）' })
  requestFreeze(@Body() body: { address: string; reason: string }) {
    return this.regulatoryService.requestFreeze(body.address, body.reason);
  }

  @Get('audit-trail')
  @RequireApiTier('regulatory')
  @ApiOperation({ summary: '完整审计日志' })
  getAuditTrail(@Query('page') page?: string, @Query('limit') limit?: string) {
    return this.regulatoryService.getAuditTrail(
      parseInt(page || '1'),
      parseInt(limit || '50'),
    );
  }
}
