import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Param,
  Body,
  UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { BankCardService } from '@/modules/shared/finance/bank-card.service';
import { JwtAuthGuard, RolesGuard } from '@/common';
import { Roles } from '@/common/decorators/roles.decorator';
import { CreateBankCardDto, UpdateBankCardDto } from '@/modules/shared/finance/dto/bank-card.dto';

@ApiTags('平台银行卡管理(管理员)')
@Controller('admin/finance/bank-cards')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@ApiBearerAuth()
export class BankCardAdminController {
  constructor(private readonly bankCardService: BankCardService) {}

  @Get()
  @ApiOperation({ summary: '查询平台银行卡列表' })
  async getBankCards() {
    const cards = await this.bankCardService.getBankCards();
    return { items: cards, total: cards.length };
  }

  @Get(':id')
  @ApiOperation({ summary: '查询银行卡详情' })
  async getBankCardById(@Param('id') id: number) {
    return this.bankCardService.getBankCardById(id);
  }

  @Post()
  @ApiOperation({ summary: '添加银行卡' })
  async createBankCard(@Body() dto: CreateBankCardDto) {
    return this.bankCardService.createBankCard(dto);
  }

  @Put(':id')
  @ApiOperation({ summary: '更新银行卡' })
  async updateBankCard(@Param('id') id: number, @Body() dto: UpdateBankCardDto) {
    return this.bankCardService.updateBankCard(id, dto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除银行卡' })
  async deleteBankCard(@Param('id') id: number) {
    await this.bankCardService.deleteBankCard(id);
    return { message: '删除成功' };
  }
}
