package com.takensoft.cms.search.web;

import com.takensoft.cms.search.service.SearchService;
import com.takensoft.cms.search.vo.SearchResultVO;
import com.takensoft.cms.search.vo.SearchVO;
import com.takensoft.common.message.MessageCode;
import com.takensoft.common.util.ResponseData;
import com.takensoft.common.util.ResponseUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.nio.charset.Charset;
/**
 * @author 하석형
 * @since 2024.06.12
 * @modification
 *     since    |    author    | description
 *  2024.06.12  |    하석형     | 최초 등록
 *
 * 통합 검색 관련 Controller
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/sys/search")
public class SearchController {

    private final SearchService searchService;
    private final ResponseUtil resUtil;

    /**
     * @author 하석형
     * @since  2024.06.11
     * @param  searchVO
     * @return
     * @throws Exception
     *
     * 통합 검색
     */
    @PostMapping("/totalSearch.json")
    public ResponseEntity<?> totalSearch(@RequestBody SearchVO searchVO) throws Exception {
        SearchResultVO result = searchService.searchAll(searchVO);

        // 응답 처리
        return resUtil.successRes(result, MessageCode.COMMON_SUCCESS);
    }
}