import { Controller, Get, UseGuards, Res, Req, Body, ValidationPipe, Post, HttpCode, Ip, HostParam, HttpStatus, Put, Param, Patch } from '@nestjs/common';

import { TokenDto } from './dto/token.dto';
//import { AuthGuard } from '@nestjs/passport';
import * as config from 'config';
import { AuthCreadentialsDto } from './dto/auth-credentials.dto';
import { AuthService } from './auth.service';
import { TempSignUpDto } from './dto/temp-sign-up.dto';
import { AuthGuard } from '@nestjs/passport';
import { GetUser } from './dto/get-user.decorator';
import { Pcduser } from './pcduser.entity';
import { PcduserDto } from './dto/pcd-user.dto';
import { Cron } from '@nestjs/schedule';
import { ChangePasswordDto } from './dto/change-password.dto';
import { UserBankDto } from './dto/user-bank.dto';

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

    @Post('/user-info')
    async userInfo(@Body() authCredentialDto:AuthCreadentialsDto){
        return this.authService.userInfo(authCredentialDto)
    }


    
    @Post('/signin')
    async signIn(@Body(ValidationPipe) 
    authCredentialDto: AuthCreadentialsDto,
     @Req() req): Promise<TokenDto> {
        return this.authService.signIn(authCredentialDto, req.ip);
    }

    // @Post('/tpin')
    // async validateTransactionPassword(@Body(ValidationPipe) authCredentialDto: AuthCreadentialsDto, @Req() req): Promise<any> {
    //     console.log(authCredentialDto);
    //     return this.authService.validateTransactionPassword(authCredentialDto);
    // }

    @Get()
    async getall() {
        return this.authService
    }


    

    @Post('/signup')
    async signUp(@Body() pcdUserDto: PcduserDto): Promise<any> {
        // request.connection.remoteAddress
        console.log("hello");
        
        return this.authService.tempSignUp(pcdUserDto);
    }
    
    @Post('/forgot-password')
    async forgotPassword(
        @Body() body: { pass: string, email: string ,otp:string },
    ): Promise<any> {
        return await this.authService.forgotPassword(body);
    }

    @Post('/otp/:flag')
    async sendOtp(
        @Body() body: { email: string},
        @Param('flag') flag: string
    ): Promise<void> {
        return await this.authService.sendOtp(body, flag );
    }

    // @Post('/resend-otp/:flag')
    // async resendOtp(
    //     @Body() body: { code?: string | number, email?: string, mobile: string },
    //     @Param('flag') flag: string
    // ): Promise<void> {
    //     return await this.authService.resendOtp(body,flag);
    // }

    @Post('/verifyOtp/:flag')
    async verifyOtp(
        @Body() body: { otp: string, email: string },
        @Param('flag') flag: string
    ): Promise<any> {
        return await this.authService.verifyOtp(body, flag);
    }

 

    // @Get('/encrypt/:bc')
    // async encryptBankCode(@GetUser() user: Pcduser,
    // @Param('bc') bankCode: string) {
    //     return await this.authService.encryptBankCode(bankCode);

    // }
}


@UseGuards(AuthGuard())
@Controller('pcduser')
export class AuthUserController {

    constructor(
        private authService: AuthService
    ) { }

 

    // @Put('/:id')
    // async updateUser(
    //     @Body() body: PcduserDto,
    //     @GetUser() user: PcduserDto,
    //     @Param('id') id: string,
    // ): Promise<PcduserDto> {
    //     return await this.authService.updateUser(body, user, id);
    // }

    // @Patch('change-password')
    // async changePasswordCurrentUser(
    //     @Body(ValidationPipe) passwords: ChangePasswordDto,
    //     @GetUser() user: PcduserDto
    // ): Promise<{ msg: string }> {
    //     return await this.authService.changePasswordCurrentUser(passwords, user.userId, user);
    // }
    // @Patch('change-tpin')
    // async changeTpinCurrentUser(
    //     @Body(ValidationPipe) passwords: ChangePasswordDto,
    //     @GetUser() user: PcduserDto
    // ): Promise<{ msg: string }> {
      
    //     return await this.authService.changeTransactionPinCurrentUser(passwords, user.userId, user);
    // }
   

    
}