import {
  Controller,
  Get,
  Post,
  Param,
  Body,
  Query,
  UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { WithdrawalService } from '@/modules/shared/finance/withdrawal.service';
import { JwtAuthGuard } from '@/common';
import { CurrentUser } from '@/common/decorators/current-user.decorator';
import {
  CreateUserWithdrawalDto,
  QueryUserWithdrawalDto,
} from '@/modules/shared/finance/dto/withdrawal.dto';

@ApiTags('提现管理(用户)')
@Controller('app/finance/withdrawals')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
export class WithdrawalUserController {
  constructor(private readonly withdrawalService: WithdrawalService) {}

  @Post()
  @ApiOperation({ summary: '用户申请提现' })
  async createWithdrawal(
    @CurrentUser('sub') userId: number,
    @Body() dto: CreateUserWithdrawalDto,
  ) {
    return this.withdrawalService.createUserWithdrawal(userId, dto);
  }

  @Get()
  @ApiOperation({ summary: '用户查询提现记录' })
  async getWithdrawals(
    @CurrentUser('sub') userId: number,
    @Query() dto: QueryUserWithdrawalDto,
  ) {
    return this.withdrawalService.getUserWithdrawals({
      userId,
      status: dto.status,
      page: dto.page,
      pageSize: dto.pageSize,
    });
  }

  @Get(':id')
  @ApiOperation({ summary: '用户查询提现详情' })
  async getWithdrawalDetail(
    @CurrentUser('sub') userId: number,
    @Param('id') id: number,
  ) {
    // TODO: 实现查询提现详情，需要验证提现记录属于当前用户
    return { message: '功能开发中' };
  }
}
