package org.jeecg.modules.system.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.system.app.entity.AppSearchHot;
import org.jeecg.modules.system.app.service.IAppSearchHotService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Tag(name="WEB热词相关接口")
@RestController
@RequestMapping("/web/search")
@Slf4j
public class WebSearchHotController {
    @Resource
    private IAppSearchHotService webSearchHotService;
    /**
     * @Author SheepHy
     * @Description 查询全部热词
     * @Date 9:52 2025/8/6
     * @Param
     * @return
     **/
    @GetMapping("/getHotSearch")
    @Operation(summary = "查询全部热词")
    public Result<IPage<AppSearchHot>> getHotSearch(@RequestParam(value = "name", required = false) String name,
                                                    @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                    @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
        Page<AppSearchHot> page = new Page<>(pageNo, pageSize);
        return Result.ok(webSearchHotService.getHotSearch(page,name));
    }

    /**
     * @Author SheepHy
     * @Description 添加热词
     * @Date 9:52 2025/8/6
     * @Param
     * @return
     **/
    @PutMapping("/addHotSearch")
    @Operation(summary = "添加热词")
    public Result<Boolean> addHotSearch(@RequestBody AppSearchHot appSearchHot){
        return Result.ok(webSearchHotService.addHotSearch(appSearchHot));
    }

    /**
     * @Author SheepHy
     * @Description 删除热词
     * @Date 9:52 2025/8/6
     * @Param
     * @return
     **/
    @DeleteMapping("/deleteHotSearch")
    @Operation(summary = "删除热词")
    public Result<Boolean> deleteHotSearch(@RequestParam String id){
        return Result.ok(webSearchHotService.deleteHotSearch(id));
    }

    /**
     * @Author SheepHy
     * @Description 修改热词
     * @Date 9:52 2025/8/6
     * @Param
     * @return
     **/
    @PutMapping("/updateHotSearch")
    @Operation(summary = "修改热词")
    public Result<Boolean> updateHotSearch(@RequestBody AppSearchHot appSearchHot){
        return Result.ok(webSearchHotService.updateHotSearch(appSearchHot));
    }

    /**
     * @Author SheepHy
     * @Description 获取热词详情
     * @Date 9:52 2025/8/6
     * @Param
     * @return
     **/
    @GetMapping("/getHotSearchById")
    @Operation(summary = "获取热词详情")
    public Result<AppSearchHot> getHotSearchById(@RequestParam String id){
        return Result.ok(webSearchHotService.getHotSearchById(id));
    }
}
