import { Body, Controller, Delete, Post } from '@nestjs/common';
import { ExcludePrivilege, Public } from 'src/core/guards';
import { AuthOrchestrator } from '../domain/auth.orchestrator';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ForceLogoutDto, LoginDto } from './dto/login.dto';

@Controller('v1/auth')
export class AuthController {
  constructor(private orchestrator: AuthOrchestrator) {}

  @Post()
  @Public(true)
  async login(@Body() body: LoginDto) {
    return await this.orchestrator.login(body);
  }

  @ApiBearerAuth('JWT')
  @Public(false)
  @ExcludePrivilege()
  @Delete('logout')
  async logout() {
    return await this.orchestrator.logout();
  }

  @Post('force-logout')
  @Public(true)
  async forceLogout(@Body() body: ForceLogoutDto) {
    return await this.orchestrator.forceLogout(body.token);
  }
}
