import { Body, Controller, HttpCode, Post } from '@nestjs/common';
import {
  ActivateRequestSchema,
  LoginRequestSchema,
  type ActivateRequest,
  type LoginRequest,
} from '@siop/shared';
import { ZodValidationPipe } from '../common/zod-validation.pipe';
import { AuthService } from './auth.service';
import { Public } from './public.decorator';

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

  @Public()
  @Post('login')
  @HttpCode(200)
  login(@Body(new ZodValidationPipe(LoginRequestSchema)) body: LoginRequest) {
    return this.authService.login(body.email, body.password);
  }

  /** Publique par nature : la personne n'a pas encore de compte actif. */
  @Public()
  @Post('activate')
  @HttpCode(200)
  activate(@Body(new ZodValidationPipe(ActivateRequestSchema)) body: ActivateRequest) {
    return this.authService.activate(body.token, body.password);
  }
}
