// api/src/feacture/auth/auth.controller.ts
import { Public } from '@/common/decorators';
import { SignInUserDto } from '@/features/auth/dto/signIn-user.dto';
import { SignOutUserDto } from '@/features/auth/dto/signOut-user.dto';
import { SingUpUserDto } from '@/features/auth/dto/signUp-user.dto';
import { Body, Controller, HttpCode, Patch, Post } from '@nestjs/common';
import { AuthService } from './auth.service';

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

  @Public()
  @HttpCode(200)
  @Post('sing-up')
  // @ApiOperation({ summary: 'Create a new user' })
  // @ApiResponse({ status: 201, description: 'User created successfully.' })
  async singUp(@Body() payload: SingUpUserDto) {
    const data = await this.authService.singUp(payload);
    return { message: 'User created successfully', data };
    // return { message: 'User created successfully', data };
  }

  @Public()
  @HttpCode(200)
  @Post('sign-in')
  async signIn(@Body() signInUserDto: SignInUserDto) {
    return await this.authService.signIn(signInUserDto);
  }

  @Public()
  @HttpCode(200)
  @Post('sign-out')
  //@RequirePermissions('auth:sign-out')
  async signOut(@Body() signOutUserDto: SignOutUserDto) {
    await this.authService.signOut(signOutUserDto);
    return { message: 'User signed out successfully' };
  }

  // @Post('forgot-password')
  // async forgotPassword(@Body() forgotPasswordDto: ForgotPasswordDto) {
  //   await this.authService.forgotPassword(forgotPasswordDto);
  //   return { message: 'Password reset link sent to your email' };
  // }

  // @UseGuards(JwtRefreshGuard)
  @Public()
  @HttpCode(200)
  @Patch('refresh')
  //@RequirePermissions('auth:refresh-token')
  async refreshToken(@Body() refreshTokenDto: any) {
    // console.log('REFRESCANDO');
    // console.log(refreshTokenDto);
    // console.log('-----------');

    return await this.authService.refreshToken(refreshTokenDto);
  }

  // @Public()
  // @HttpCode(200)
  // @Get('test')
  // async test() {
  //   return 'aplication test success';
  // }
}
