import {
  Controller,
  Get,
  Param,
  Query,
  UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { AccountService } from '@/modules/shared/finance/account.service';
import { JwtAuthGuard, RolesGuard } from '@/common';
import { Roles } from '@/common/decorators/roles.decorator';
import { QueryUserAccountsDto, QueryMerchantAccountsDto } from '@/modules/shared/finance/dto/account.dto';

@ApiTags('账户管理(管理员)')
@Controller('admin/finance/accounts')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@ApiBearerAuth()
export class AccountAdminController {
  constructor(private readonly accountService: AccountService) {}

  // ==================== 平台账户管理 ====================

  @Get('platform')
  @ApiOperation({ summary: '查询平台账户列表' })
  async getPlatformAccounts() {
    return this.accountService.getPlatformAccounts();
  }

  @Get('platform/:id')
  @ApiOperation({ summary: '查询平台账户详情' })
  async getPlatformAccountDetail(@Param('id') id: number) {
    return this.accountService.getPlatformAccountDetail(id);
  }

  @Get('platform/:id/balance')
  @ApiOperation({ summary: '查询平台账户余额' })
  async getPlatformAccountBalance(@Param('id') id: number) {
    return this.accountService.getPlatformAccountBalance(id);
  }

  // ==================== 用户账户管理 ====================

  @Get('users')
  @ApiOperation({ summary: '查询用户账户列表' })
  async getUserAccounts(@Query() dto: QueryUserAccountsDto) {
    return this.accountService.getUserAccounts(dto);
  }

  @Get('users/:userId')
  @ApiOperation({ summary: '查询用户账户详情' })
  async getUserAccountDetail(@Param('userId') userId: number) {
    return this.accountService.getUserAccountDetail(userId);
  }

  @Get('users/summary')
  @ApiOperation({ summary: '用户账户汇总统计' })
  async getUserAccountsSummary() {
    return this.accountService.getUserAccountsSummary();
  }

  // ==================== 商家账户管理 ====================

  @Get('merchants')
  @ApiOperation({ summary: '查询商家账户列表' })
  async getMerchantAccounts(@Query() dto: QueryMerchantAccountsDto) {
    return this.accountService.getMerchantAccounts(dto);
  }

  @Get('merchants/:merchantId')
  @ApiOperation({ summary: '查询商家账户详情' })
  async getMerchantAccountDetail(@Param('merchantId') merchantId: number) {
    return this.accountService.getMerchantAccountDetail(merchantId);
  }

  @Get('merchants/summary')
  @ApiOperation({ summary: '商家账户汇总统计' })
  async getMerchantAccountsSummary() {
    return this.accountService.getMerchantAccountsSummary();
  }
}
