import {
  Controller,
  Get,
  UseGuards,
  Req,
  HttpStatus,
} from '@nestjs/common';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiBearerAuth,
} from '@nestjs/swagger';
import { PlantingApplicationService } from '../../application/services/planting-application.service';
import { PlantingPositionResponse } from '../dto/response/planting-position.response';
import { JwtAuthGuard } from '../guards/jwt-auth.guard';

interface AuthenticatedRequest {
  user: { id: string };
}

@ApiTags('认种持仓')
@ApiBearerAuth()
@Controller('planting')
@UseGuards(JwtAuthGuard)
export class PlantingPositionController {
  constructor(
    private readonly plantingService: PlantingApplicationService,
  ) {}

  @Get('position')
  @ApiOperation({ summary: '查询我的持仓' })
  @ApiResponse({
    status: HttpStatus.OK,
    description: '持仓信息',
    type: PlantingPositionResponse,
  })
  async getUserPosition(
    @Req() req: AuthenticatedRequest,
  ): Promise<PlantingPositionResponse> {
    const userId = BigInt(req.user.id);
    return this.plantingService.getUserPosition(userId);
  }
}
