import { Controller, HttpCode, Post, Request, UseGuards } from "@nestjs/common";
import type { Request as ExpressRequest } from "express";
import { LocalAuthGuard } from "../auth/local-auth.guard.js";
import { AuthService } from "../services/auth.service.js";

@Controller("auth")
export class AuthController {
  constructor(private authService: AuthService) {}

  @UseGuards(LocalAuthGuard)
  @HttpCode(200)
  @Post("login")
  async login(@Request() req: ExpressRequest): Promise<{ auth_token: string }> {
    return this.authService.login(req.user);
  }
}
