import { Body, Controller, Post } from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiCreatedResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { AuthUserService } from './authUserservice';
import { CreateUserDto } from 'src/user/dto/create-user.dto';
import { LoginUserDto } from './dto/login-user.dto';
import { UserSigninResDto } from './dto/user-signin-res.dto';

@Controller('')
@ApiTags('Create user account and sign in as user')
export class AuthUserController {
  constructor(private readonly authUserService: AuthUserService) {}

  @ApiBody({ type: CreateUserDto })
  @ApiBearerAuth()
  @ApiCreatedResponse({
    type: UserSigninResDto,
  })
  @Post('user/signup')
  async signUp(@Body() createAdminDto: CreateUserDto) {
    try {
      const adminSigninResDto = await this.authUserService.signUp(createAdminDto);
      return { user: adminSigninResDto };
    } catch (e) {
      throw e;
    }
  }
  @ApiBody({ type: LoginUserDto })
  @ApiCreatedResponse({
    type: UserSigninResDto,
  })
  @ApiUnauthorizedResponse()
  @Post('user/signin')
  async signIn(@Body() loginAdminDto: LoginUserDto) {
    try {
      const userSigninResDto = await this.authUserService.signIn(loginAdminDto);
      return { user: userSigninResDto };
    } catch (e) {
      throw e;
    }
  }
}
