import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { DashboardService } from "./dashboard.service";
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import * as dto from './dto/index';
import { AuthGuard } from '../auth/auth.guard';

@ApiTags('Dashboard')
@Controller('dashboard')
export class DashboardController {

    constructor(
        private readonly DashboardService: DashboardService
    ) { }


    @UseGuards(AuthGuard)
    @ApiBearerAuth('authorization')
    @Get("/calls")
    async getAnswer(@Query() body: dto.Dashboard.getAgents) {
        try {
            try {
                console.time('Total time');
                let data = await this.DashboardService.getAgentsWithCalls(body)
                console.timeEnd('Total time');
                return data
            } catch (error) {
                throw error
            }
        } catch (error) {
            throw error
        }
    }

    @UseGuards(AuthGuard)
    @ApiBearerAuth('authorization')
    @Get("/chats")
    async getAgentChat(@Query() body: dto.Dashboard.getAgents) {
        try {
            try {
                let data = await this.DashboardService.getAgentsWithChats(body)
                return data
            } catch (error) {
                throw error
            }
        } catch (error) {
            throw error
        }
    }

    @UseGuards(AuthGuard)
    @ApiBearerAuth('authorization')
    @Get("/counts")
    async getVendorDashboardCount() {
        try {
            try {
                let data = await this.DashboardService.getVendorDashboardCounts()
                return data
            } catch (error) {
                throw error
            }
        } catch (error) {
            throw error
        }
    }
}
