import { Body, Controller, Get, Put, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { UploadSettingsService } from './upload-settings.service';
import {
  UpdateUploadSettingsDto,
  type UploadSettingsVo,
} from './upload-settings.dto';
import { JwtAuthGuard } from '../../auth/guards/JwtAuthGuard';
import { Roles } from '../../auth/decorators/RolesDecorator';
import { RolesGuard } from '../../auth/guards/RolesGuard';

@ApiTags('Settings/Upload')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('super', 'admin')
@Controller('settings/upload')
export class UploadSettingsController {
  constructor(private readonly service: UploadSettingsService) {}

  @Get()
  @ApiOperation({ summary: '获取上传设置' })
  async get(): Promise<{ code: number; data: UploadSettingsVo }> {
    const data = await this.service.getSettings();
    return { code: 0, data };
  }

  @Put()
  @ApiOperation({ summary: '更新上传设置' })
  async update(
    @Body() dto: UpdateUploadSettingsDto,
  ): Promise<{ code: number; data: UploadSettingsVo }> {
    const data = await this.service.updateSettings(dto);
    return { code: 0, data };
  }
}
