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

@ApiTags('Settings/Email')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('super', 'admin')
@Controller('settings/email')
export class EmailSettingsController {
  constructor(private readonly service: EmailSettingsService) {}

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

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