import { Controller, Post, Body } from '@nestjs/common';
import {
  AdminLoginGoogle,
  ChangePassword,
  TenantSignUp,
  UserConfirmSignUp,
  UserLogin,
  UserSignUp,
} from './dto/login.dto';
import { AuthService } from './auth.service';
import { Public } from './decorators/public.auth';
import { RefreshTokenDto } from './dto/refresh-token.dto';
import { AuthUser } from 'src/common/auth/decorators';
import { AuthPayload } from './decorators/auth.payload';

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

  @Public()
  @Post('login')
  async loginByUsername(@Body() body: UserLogin) {
    return await this.authService.userLogin(body);
  }

  @Public()
  @Post('/sign-up')
  async registerUser(@Body() body: UserSignUp) {
    return await this.authService.signUpUser(body);
  }

  @Post('/change-password')
  async changePassword(
    @Body() body: ChangePassword,
    @AuthUser() user: AuthPayload,
  ) {
    return await this.authService.changePassword(body, user);
  }

  // @Public()
  // @Post('/confirm-sign-up')
  // async confirmSignUp(@Body() body: UserConfirmSignUp) {
  //   return await this.authService.confirmSignUpUser(body);
  // }

  @Public()
  @Post('login-google')
  async loginGoogle(@Body() googleLogin: AdminLoginGoogle) {
    return await this.authService.userLoginByGoogleOAuth2(
      googleLogin.google_token,
    );
  }

  @Public()
  @Post('refresh-token')
  async userRefreshToken(@Body() data: RefreshTokenDto) {
    return await this.authService.refreshToken(data.refresh_token);
  }

  @Public()
  @Post('tenant/login')
  async userLogin(@Body() data: UserLogin) {
    return await this.authService.tenantLogin(data);
  }

  @Public()
  @Post('tenant/sign-up')
  async registerTenant(@Body() data: TenantSignUp) {
    return await this.authService.signUpTenant(data);
  }
}
