import { Controller, Get, HttpStatus, Query, Res, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiResponse as SwaggerApiResponse, ApiTags } from '@nestjs/swagger';
import { Response } from 'express';
import { CurrentUser } from '../../gateway/auth/current_user.decorator';
import { JwtAuthGuard } from '../../gateway/auth/jwt_auth.guard';
import { JwtPayload } from '../../core/login_core/login_core.service';
import { InventoryService } from './inventory.service';
import { PlayerAssetType } from './player.types';

@ApiTags('inventory')
@ApiBearerAuth()
@Controller('inventory')
@UseGuards(JwtAuthGuard)
export class InventoryController {
  constructor(private readonly inventoryService: InventoryService) {}

  @ApiOperation({ summary: '获取当前玩家背包资产' })
  @SwaggerApiResponse({ status: 200, description: '背包资产获取成功' })
  @Get()
  async listInventory(
    @CurrentUser() user: JwtPayload,
    @Query('type') type: PlayerAssetType | undefined,
    @Res() res: Response,
  ): Promise<void> {
    const data = await this.inventoryService.listInventory(BigInt(user.sub), type);
    res.status(HttpStatus.OK).json({ success: true, data, message: '背包资产获取成功' });
  }
}
