import { Controller, All, Req, Get, UseGuards } from "@nestjs/common";
import type { AuthUser } from "@mosaic/shared";
import { AuthService } from "./auth.service";
import { AuthGuard } from "./guards/auth.guard";
import { CurrentUser } from "./decorators/current-user.decorator";

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

  @Get("profile")
  @UseGuards(AuthGuard)
  getProfile(@CurrentUser() user: AuthUser) {
    return {
      id: user.id,
      email: user.email,
      name: user.name,
    };
  }

  @All("*")
  async handleAuth(@Req() req: Request) {
    const auth = this.authService.getAuth();
    return auth.handler(req);
  }
}
