//src/auth/auth.controller.ts

import { Body, Controller, HttpCode, Post } from '@nestjs/common';
import { AuthService } from './auth.service';
import { ApiOkResponse, ApiResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { AuthEntity } from './entity/auth.entity';
import { LoginDto, TokenDto } from './dto/login.dto';

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

	@Post('login')
	@ApiOkResponse({ type: AuthEntity })
	login(@Body() { email, password }: LoginDto) {
		return this.authService.login(email, password);
	}

	@Post('verify')
	@HttpCode(200)
	@ApiOkResponse({ description: 'token is valid' })
	@ApiResponse({ status: 401, description: 'token is invalid' })
	verify(@Body() { email, token }: TokenDto) {
		return this.authService.validateToken(email, token);
	}
}
