import { Controller, Get, Put, Body, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { ConfigService } from './config.service';
import { JwtAuthGuard, RolesGuard, Roles } from '@/common';
import { UploadService } from '../upload/upload.service';

@ApiTags('管理端-系统配置')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@Controller('admin/config')
export class ConfigController {
  constructor(
    private readonly configService: ConfigService,
    private readonly uploadService: UploadService,
  ) {}

  @Get('service-fee')
  @ApiOperation({ summary: '获取服务费配置' })
  async getServiceFeeConfig() {
    return this.configService.getServiceFeeConfig();
  }

  @Put('service-fee')
  @ApiOperation({ summary: '更新服务费配置' })
  async updateServiceFeeConfig(@Body() body: { rate: number }) {
    await this.configService.updateServiceFeeRate(body.rate);
    return this.configService.getServiceFeeConfig();
  }

  @Get('storage')
  @ApiOperation({ summary: '获取存储配置' })
  async getStorageConfig() {
    return this.uploadService.getStorageConfig();
  }

  @Put('storage')
  @ApiOperation({ summary: '更新存储配置' })
  async updateStorageConfig(@Body() body: Record<string, string>) {
    await this.uploadService.updateStorageConfig(body);
    return this.uploadService.getStorageConfig();
  }
}