import { Body, Controller, Post, 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 { ThirdPartyOrderListSyncDto } from './dto/orders.dto';
import { OrdersService } from './orders.service';

@UseGuards(AuthGuard)
@Controller('api/admin/third-party/orders')
export class OrdersThirdPartyAdminController {
  constructor(private readonly ordersService: OrdersService) {}

  @Post('sync')
  @OperationLog({
    action: 'third_party.orders.sync',
    resourceType: 'order',
    metadataFromBody: ['page', 'limit', 'recent'],
    description: '拉取第三方订单列表并同步本地订单',
  })
  syncThirdPartyOrderList(
    @Req() request: AuthenticatedRequest,
    @Body() dto: ThirdPartyOrderListSyncDto,
  ) {
    return this.ordersService.syncThirdPartyOrderList(request.user, dto);
  }
}
