package com.keyware.shandan.browser.controller;

import com.keyware.shandan.browser.SearchLogProcessor;
import com.keyware.shandan.common.entity.Result;
import com.keyware.shandan.frame.config.security.SecurityUtil;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 搜索建议前端控制器
 */
@RestController
@RequestMapping("/search/suggest")
public class SearchSuggestController {

    private final SearchLogProcessor logProcessor;

    public SearchSuggestController(SearchLogProcessor logProcessor) {
        this.logProcessor = logProcessor;
    }

    @GetMapping("/user/history")
    public Result<Object> getUserHistory() {
        String loginName = SecurityUtil.getLoginUsername();
        return Result.of(logProcessor.getUserSearchHistory(loginName));
    }

    @GetMapping("/system/words")
    public Result<Object> getSystemWords() {
        return Result.of(logProcessor.getSystemWords());
    }
}
