import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
  Query,
  UseGuards,
  Request,
  Patch,
} from '@nestjs/common';
// import { AuthGuard } from 'src/auth/auth.guard';

import { ApiBearerAuth, ApiTags, ApiOperation } from '@nestjs/swagger';
import * as dto from './dto/index';
import { AdminService } from './admin.service';
import { Commission } from './dto/admin';
import { AuthGuard } from '../auth/auth.guard';
// import { RolesGuard } from 'src/auth/roles.guard';

@ApiTags('Admin')
@Controller('admin')
export class AdminController {
  constructor(private readonly AdminService: AdminService) { }

  @Post('login')
  async login(@Body() dto: dto.adminLogin) {
    try {
      let data = await this.AdminService.login(dto);
      let response = {
        success: true,
        message:
          "Welcome back! You've successfully logged into your account. Feel free to explore and enjoy our services",
        data: data,
      };
      return response;
    } catch (err) {
      throw err;
    }
  }

  @Get('profile')
  @UseGuards(AuthGuard)
  @ApiBearerAuth('authorization')
  async admin_profile(@Request() req: any) {
    try {
      let data = await this.AdminService.admin_profile(req);
      let response = {
        success: true,
        message: "Success",
        data: data,
      };
      return response;
    } catch (err) {
      throw err;
    }
  }

  @Put('profile')
  @UseGuards(AuthGuard)
  @ApiBearerAuth('authorization')
  async edit_admin_profile(@Body() dto: dto.editProfile, @Request() req: any) {
    try {
      let data = await this.AdminService.edit_profile(dto, req);
      let response = {
        message: 'Logged in',
        data: data,
      };
      return response;
    } catch (err) {
      throw err;
    }
  }

  @UseGuards(AuthGuard)
  @ApiBearerAuth('authorization')
  @Put('password')
  async admin_change_password(
    @Body() dto: dto.adminChangePass,
    @Request() req: any
  ) {
    try {
      let data = await this.AdminService.changePassword(dto, req);
      let response = {
        message:
          'Your password has been changed successfully. You can now log in with your new password.',
        data: data,
      };
      return response;
    } catch (err) {
      throw err;
    }
  }

  @UseGuards(AuthGuard)
  @ApiBearerAuth('authorization')
  @Get('call')
  async call_list(
    @Query() dto: dto.call.callList,
    @Request() req: any
  ) {
    try {
      let data = await this.AdminService.call_list(dto);
      let response = {
        message: "success",
        success: true,
        count: data.count,
        data: data.data,
      };
      return response;
    } catch (err) {
      throw err;
    }
  }

  @UseGuards(AuthGuard)
  @ApiBearerAuth('authorization')
  @Get('call/:_id')
  async call_detail(
    @Param("_id") call_id: string,
    @Request() req: any
  ) {
    try {
      console.log("call_id",call_id);
      
      let data = await this.AdminService.call_detail(call_id);
      let response = {
        message: "success",
        success: true,
        data: data,
      };
      return response;
    } catch (err) {
      throw err;
    }
  }


  @UseGuards(AuthGuard)
  @ApiBearerAuth('authorization')
  @Get('call/:_id/transcript')
  async call_transcript(
    @Param("_id") call_id: string,
    @Request() req: any
  ) {
    try {
      let data = await this.AdminService.call_transcript(call_id);
      let response = {
        message: "success",
        success: true,
        data: data.data,
      };
      return response;
    } catch (err) {
      throw err;
    }
  }

  @UseGuards(AuthGuard)
  @ApiBearerAuth('authorization')
  @Get('dashboard')
  async dashboard(
    @Query() body: dto.DashboardApi,
    @Request() req: any
  ) {
    try {
      let data = await this.AdminService.dashboard(body);
      let response = {
        message: "success",
        success: true,
        data: data,
      };
      return response;
    } catch (err) {
      throw err;
    }
  }

}
