import { Body, Controller, Get, Post, Query, Req, UseGuards } from '@nestjs/common';
import { OperationLog } from '../audit/operation-log.decorator';
import { AuthGuard } from '../auth/auth.guard';
import type { AuthenticatedRequest } from '../auth/types/authenticated-request';
import type {
  OrderLogHistoryQuery,
  QueryStreamOrderLogDto,
  QueryThirdPartyOrderLogDto,
} from './dto/order-logs.dto';
import { OrderLogsService } from './order-logs.service';

@UseGuards(AuthGuard)
@Controller('api/admin/order-logs')
export class OrderLogsController {
  constructor(private readonly orderLogsService: OrderLogsService) {}

  @Post('query')
  @OperationLog({
    action: 'order_logs.query',
    resourceType: 'order_log',
    metadataFromBody: ['orderId', 'type'],
    description: '查询第三方订单日志',
  })
  queryThirdPartyLog(
    @Req() request: AuthenticatedRequest,
    @Body() dto: QueryThirdPartyOrderLogDto,
  ) {
    return this.orderLogsService.queryThirdPartyLog(request.user, dto);
  }

  @Post('stream')
  @OperationLog({
    action: 'order_logs.stream',
    resourceType: 'order_log',
    metadataFromBody: ['orderId'],
    description: '查询第三方 Stream 日志',
  })
  queryStreamLog(
    @Req() request: AuthenticatedRequest,
    @Body() dto: QueryStreamOrderLogDto,
  ) {
    return this.orderLogsService.queryStreamLog(request.user, dto);
  }

  @Get('history')
  listHistory(
    @Req() request: AuthenticatedRequest,
    @Query() query: OrderLogHistoryQuery,
  ) {
    return this.orderLogsService.listHistory(request.user, query);
  }
}
