package kr.gmtc.gw.elastic.test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import kr.gmtc.gw.elastic.services.ElkSearchService;


@RestController
@RequestMapping("/")
public class SearchController {
    
    private ElkSearchService elkSearchService;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public SearchController(ElkSearchService elkSearchService){
        this.elkSearchService = elkSearchService;
    }
    
    // http://localhost:8080/replay?idx=2&s=20240429145000.000&e=20240429145500.999
    @GetMapping("/replay")
    @ResponseBody
    public String processSearch_replay_loop(@RequestParam(value = "idx", required = false) String sIndex,
                                            @RequestParam(value = "s", required = false) String sStartDt,
                                            @RequestParam(value = "e", required = false) String sEndDt) {

        logger.info("searching by Index {}", sIndex);
        String IndexFusion = elkSearchService.elkSearch_replay_log(sIndex, sStartDt, sEndDt);

        return IndexFusion;

    }

}
