package com.dbnt.kcscopensearch.opensearch.docSearch;

import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocContent;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocIndex;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocTitle;
import com.dbnt.kcscopensearch.opensearch.docSearch.service.DocSearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
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.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/doc-search")
public class DocSearchController {
  private final DocSearchService docSearchService;

  @GetMapping(value="/doc-title", produces = MediaType.APPLICATION_JSON_VALUE)
  public List<DocTitle> searchTitle (@RequestParam(value="searchText", required = true) String text, @RequestParam(value="pageNum", required = true) Integer pageNum){
    return docSearchService.selectDocTitle(text, pageNum);
  }
  @GetMapping(value="/doc-index", produces = MediaType.APPLICATION_JSON_VALUE)
  public List<DocIndex> searchIndex (@RequestParam(value="searchText", required = true) String text, @RequestParam(value="pageNum", required = true) Integer pageNum){
    return docSearchService.selectDocIndex(text, pageNum);
  }
  @GetMapping(value="/doc-content", produces = MediaType.APPLICATION_JSON_VALUE)
  public List<DocContent> searchContent (@RequestParam(value="searchText", required = true) String text, @RequestParam(value="pageNum", required = true) Integer pageNum){
    return docSearchService.selectDocContent(text, pageNum);
  }
}
