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

@ApiTags('Settings/Login')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('super', 'admin')
@Controller('settings/login')
export class LoginSettingsController {
  constructor(private readonly service: LoginSettingsService) {}

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

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