package cn.reghao.tnb.content.app.vod.controller;

import cn.reghao.jutil.jdk.web.db.PageList;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.content.app.vod.model.vo.HotSearch;
import cn.reghao.tnb.content.app.vod.model.vo.SuggestKeyword;
import cn.reghao.tnb.content.api.dto.VideoCard;
import cn.reghao.tnb.content.app.vod.service.SearchService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
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;

/**
 * @author reghao
 * @date 2023-08-26 21:27:07
 */
@Tag(name = "搜索接口")
@RestController
@RequestMapping("/api/search")
public class SearchController {
    private final SearchService searchService;

    public SearchController(SearchService searchService) {
        this.searchService = searchService;
    }

    @Operation(summary = "获取推荐的搜索关键词", description = "N")
    @GetMapping(value = "/suggest", produces = MediaType.APPLICATION_JSON_VALUE)
    public String keywordSuggest(@RequestParam("keyword") String keyword) {
        List<SuggestKeyword> list = searchService.suggestKeyword(keyword);
        return WebResult.success(list);
    }

    @Operation(summary = "查询关键词", description = "N")
    @GetMapping(value = "/query", produces = MediaType.APPLICATION_JSON_VALUE)
    public String similarVideoPostList(@RequestParam("keyword") String keyword,
                                       @RequestParam("pageNumber") int pageNumber,
                                       @RequestParam(value = "nextId", required = false) String nextId) {
        PageList<VideoCard> pageScroll = searchService.searchByKeyword(keyword, nextId, pageNumber);
        return WebResult.success(pageScroll);
    }

    @Operation(summary = "获取热门搜索关键词", description = "N")
    @GetMapping(value = "/hot", produces = MediaType.APPLICATION_JSON_VALUE)
    public String hotSearch() {
        List<HotSearch> list = searchService.getHotSearch();
        return WebResult.success(list);
    }
}
