package com.bytesw.bytebot.controller;

import com.bytesw.bytebot.bean.SummaryMessageBySentenceBean;
import com.bytesw.bytebot.service.dashboard.CustomerInteractionDashboardService;
import com.bytesw.bytebot.service.dashboard.OperativeDashboardService;
import com.bytesw.xdf.sql.beans.Pagination;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/dashboard")
public class DashboardController {

    @Autowired
    private OperativeDashboardService operativeDashboardService;

    @Autowired
    private CustomerInteractionDashboardService customerInteractionDashboardService;

    @Autowired
    private Gson gson;

    @PostMapping("/operative")
    public ResponseEntity<String> getOperativeInfo(@RequestBody Map<String, Object> body) {
        Map<String, Object> info = operativeDashboardService.generateInfo(body);
        return new ResponseEntity<>(gson.toJson(info), HttpStatus.OK);
    }

    @PostMapping("/operative/sentence-by-intent/page")
    public ResponseEntity<String> getSentenceByIntentPage(@RequestBody Pagination<SummaryMessageBySentenceBean> pagination) {
        customerInteractionDashboardService.getSummaryBySentencePagination(pagination);
        return new ResponseEntity<>(gson.toJson(pagination), HttpStatus.OK);
    }

    @PostMapping("/customer-interaction")
    public ResponseEntity<String> getCustomerInteractionInfo(@RequestBody Map<String, Object> body) {
        Map<String, Object> info = customerInteractionDashboardService.generateInfo(body);
        return new ResponseEntity<>(gson.toJson(info), HttpStatus.OK);
    }

    @PostMapping("/customer-interaction/message-by-intent/page")
    public ResponseEntity<String> getMessageByIntentPage(@RequestBody Pagination<SummaryMessageBySentenceBean> pagination) {
        customerInteractionDashboardService.getSummaryByIntentAndSentencePagination(pagination);
        return new ResponseEntity<>(gson.toJson(pagination), HttpStatus.OK);
    }

    @GetMapping("/test")
    public ResponseEntity<String> getTest() {
        Map<String, Object> data = customerInteractionDashboardService.generateInfo(new HashMap<>());
        return new ResponseEntity<>(gson.toJson(data), HttpStatus.OK);
    }
}
