import { Body, Controller, Get, Headers, Post, Query, Req, UseGuards } from "@nestjs/common";
import { AccountService } from "./account.service";
import * as DTO from "./dto";
import { JwtAccessAuthGuard } from "src/middleware/auth/guard/access-token.guard";
import { Public } from "src/common/decorators/public.decorator";

@UseGuards(JwtAccessAuthGuard)
@Controller('account')
export class AccountController {
  constructor(private readonly accountService: AccountService) {}

  @Public()
  @Get('/')
  async test() {
    return "Test"
  }

  @Public()
  @Get('check-duplication')
  async checkDuplication(@Query() query: DTO.CheckDuplicationRequest): Promise<DTO.CheckDuplicationResponse> {
    return await this.accountService.checkDuplication(query);
  }

  @Public()
  @Post('send-verification-code')
  async sendVerificationCode(@Body() body: DTO.SendVerificationCodeRequest): Promise<DTO.SendVerificationCodeResponse> {
    const result = await this.accountService.sendVerificationCode(body);
    return result;
  }

  @Public()
  @Post('verify-code')
  async verifyCode(@Body() body: DTO.VerifyCodeRequest): Promise<DTO.VerifyCodeResponse> {
    console.log(body.email);
    const result = await this.accountService.verifyCode(body);
    return result;
  }

  @Public()
  @Post('signup')
  async signup(@Body() body: DTO.SignupRequest): Promise<DTO.SignupResponse> {
    const result = await this.accountService.signup(body);
    return result;
  }

  @Public()
  @Post('login')
  async login(@Body() body: DTO.LoginRequest): Promise<DTO.LoginResponse> {
    const result = await this.accountService.login(body);
    return result;
  }

  @Public()
  @Post('refresh-access-token')
  async refreshAccessToken(@Req() req): Promise<DTO.RefreshAccessTokenResponse> {
    const id = req.user.id;
    const newAccessToken = this.accountService.refreshAccessToken(id);
    return newAccessToken;
  }
}