import {
  Controller,
  Get,
  Put,
  Body,
  Post,
  UseGuards,
  HttpCode,
  HttpStatus,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard } from '../../auth/guards/JwtAuthGuard';
import { RolesGuard } from '../../auth/guards/RolesGuard';
import { Roles } from '../../auth/decorators/RolesDecorator';
import { SiteSettingsService } from './site-settings.service';
import { UpdateSiteSettingsDto } from './site-settings.dto';

@ApiTags('站点设置')
@Controller('system/settings/basic')
@UseGuards(JwtAuthGuard, RolesGuard)
@ApiBearerAuth()
export class SiteSettingsController {
  constructor(private readonly siteSettingsService: SiteSettingsService) {}

  @Get()
  @ApiOperation({ summary: '获取站点设置' })
  @ApiResponse({ status: 200, description: '成功获取站点设置' })
  @Roles('super', 'admin')
  async getSiteSettings() {
    return this.siteSettingsService.getSiteSettings();
  }

  @Put()
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: '更新站点设置' })
  @ApiResponse({ status: 200, description: '站点设置更新成功' })
  @Roles('super', 'admin')
  async updateSiteSettings(@Body() updateSiteSettingsDto: UpdateSiteSettingsDto) {
    return this.siteSettingsService.updateSiteSettings(updateSiteSettingsDto);
  }

  @Post('reset')
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: '重置站点设置为默认值' })
  @ApiResponse({ status: 200, description: '站点设置重置成功' })
  @Roles('super')
  async resetSiteSettings() {
    return this.siteSettingsService.resetSiteSettings();
  }
}