/**
 * Auth Controller
 *
 * REST endpoints replacing COM methods:
 * - Connect() -> POST /auth/login
 * - SetDatabaseName() -> included in login or POST /auth/select-database
 */
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
import { AuthService, LoginResponse } from './auth.service';
import { LoginDto } from './dto/login.dto';
import { JwtAuthGuard } from './jwt-auth.guard';

@Controller('auth')
export class AuthController {
  constructor(private authService: AuthService) {}

  /**
   * POST /api/auth/login
   *
   * Replaces: Connect() from PublicDataImpl
   * Body: { dbName, userName, password, dbType? }
   * Returns: { accessToken, expiresIn, user }
   */
  @Post('login')
  async login(@Body() dto: LoginDto): Promise<LoginResponse> {
    return this.authService.login(dto);
  }

  /**
   * POST /api/auth/select-database
   *
   * Replaces: SetDatabaseName()
   * For multi-DB: would switch connection. With single DB, this is informational.
   * Requires valid JWT.
   */
  @Post('select-database')
  @UseGuards(JwtAuthGuard)
  async selectDatabase(@Body() body: { dbName: string }) {
    return {
      success: true,
      dbName: body.dbName,
      message: 'Database context updated (stored in token for next login)',
    };
  }
}
