package com.arms.api.search_engine.controller;

import com.arms.api.fluentd.model.vo.ScheduleHistoryVO;
import com.arms.api.fluentd.service.FluentdService;
import com.arms.api.search_engine.model.dto.BaseSearchAggrDTO;
import com.arms.api.search_engine.model.dto.SearchDTO;
import com.arms.api.issue.search.service.AlmIssueSearch;
import com.arms.api.search_engine.model.vo.SearchAggrResultVO;
import com.arms.api.wiki.service.WikiService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/engine/search")
@Slf4j
@AllArgsConstructor
public class SearchController {

    private final AlmIssueSearch almIssueSearch;

    private final FluentdService fluentdService;

    private final WikiService wikiService;

    @PostMapping("/wiki")
    public ResponseEntity<?> searchWiki(@RequestBody SearchDTO searchDTO) {
        log.info("[SearchController :: WikiSearch] :: searchString => {}" , searchDTO.getSearchString());

        return ResponseEntity.ok(wikiService.searchWiki(searchDTO));
    }

    @PostMapping("/almIssue")
    public ResponseEntity<?> searchAlmIssue(@RequestBody SearchDTO searchDTO) {
        log.info("[SearchController :: AlmIssueSearch] :: searchString => {}" , searchDTO.getSearchString());

        return ResponseEntity.ok(almIssueSearch.searchAlmIssue(searchDTO));
    }

    @PostMapping("/log")
    public ResponseEntity<?> searchFluentdLog(@RequestBody SearchDTO searchDTO) {
        log.info("[SearchController :: searchFluentdLog] :: searchString => {}", searchDTO.getSearchString());

        return ResponseEntity.ok(fluentdService.searchFluentdLog(searchDTO));
    }

    @PostMapping("/wiki/aggr-top5")
    public ResponseEntity<SearchAggrResultVO> findWikiLogAggregationDataByLogName(@RequestBody BaseSearchAggrDTO searchAggrDTO) {
        log.info("[SearchController :: findWikiLogAggregationDataByLogName]");
        //구현해야함
        return ResponseEntity.ok(new SearchAggrResultVO());
    }

    @PostMapping("/almIssue/project-aggr-top5")
    public ResponseEntity<SearchAggrResultVO> findAlmIssueAggregationDataByAlmProjectName(@RequestBody BaseSearchAggrDTO searchAggrDTO) {
        log.info("[SearchController :: findAlmIssueAggregationDataByAlmProjectName]");

        return ResponseEntity.ok(almIssueSearch.aggregateByAlmProjectName(searchAggrDTO));
    }

    @PostMapping("/log/aggr-top5")
    public ResponseEntity<SearchAggrResultVO> findFluentdLogAggregationDataByLogName(@RequestBody BaseSearchAggrDTO searchAggrDTO) {
        log.info("[SearchController :: findFluentdLogAggregationDataByLogName]");

        return ResponseEntity.ok(fluentdService.aggregateByFluentdLogName(searchAggrDTO));
    }

    @PostMapping("/schedule-history-log")
    public ResponseEntity<List<ScheduleHistoryVO>> getScheduleHistory(@RequestBody SearchDTO searchDTO) {
        log.info("[SearchController :: getScheduleHistory]");

        return ResponseEntity.ok(fluentdService.getScheduleHistory(searchDTO));
    }


}
