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

@ApiTags('Settings/Storage')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('super', 'admin')
@Controller('settings/storage')
export class StorageSettingsController {
  constructor(private readonly service: StorageSettingsService) {}

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

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