package org.jeecg.modules.app.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.app.dto.GetPlaceListDTO;
import org.jeecg.modules.app.dto.SearchDTO;
import org.jeecg.modules.app.dto.evaluate.FindEvaluateDTO;
import org.jeecg.modules.app.dto.evaluate.FindEvaluatePage;
import org.jeecg.modules.app.service.IAppHomeService;
import org.jeecg.modules.app.service.IUserService;
import org.jeecg.modules.app.vo.HomeVO;
import org.jeecg.modules.app.vo.MsgInfoVO;
import org.jeecg.modules.app.vo.MsgVO;
import org.jeecg.modules.app.vo.PlaceVO;
import org.jeecg.modules.system.app.dto.evaluate.FindEvaluateResponseDTO;
import org.jeecg.modules.system.app.entity.AppSearchHot;
import org.jeecg.modules.system.app.service.IEvaluateService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Tag(name = "App首页相关接口")
@RestController
@RequestMapping("/app/home")
public class AppHomeController {
    @Resource
    private IAppHomeService appHomeService;
    @Resource
    private IUserService userService;
    @Resource
    private IEvaluateService evaluateService;

    @GetMapping("/homeInfo")
    @Operation(summary = "首页基础数据查询")
    public Result<HomeVO> homeInfo() {
        HomeVO homeVO = appHomeService.homeInfo();
        homeVO.getInstructorList().forEach(instructorVO -> {
            FindEvaluatePage<FindEvaluateResponseDTO> byOrderPage = evaluateService.findByOrderPage(new FindEvaluateDTO().setInstructorId(instructorVO.getId()));
            instructorVO.setGoodRate(byOrderPage.getApplauseRate());
        });
        return Result.ok(homeVO);
    }
    /**
     * @Author SheepHy
     * @Description 查询消息通知列表（简略）
     * @Date 17:13 2025/7/3
     * @return List<MsgVO> {@link List<MsgVO>}
     **/
    @GetMapping("/getMsg")
    @Operation(summary = "查询消息通知列表（简略）")
    public Result<List<MsgVO>> getMsg(){
        return Result.ok(userService.getMsg());
    }

    /**
     * @Author SheepHy
     * @Description 查询消息详情
     * @Date 17:29 2025/7/3
     * @Param id 消息ID
     * @return MsgInfoVO {@link MsgInfoVO}
     **/
    @GetMapping("/getMsgInfo")
    @Operation(summary = "查询消息详情")
    public Result<MsgInfoVO> getMsgInfo(@RequestParam(required = false) @Schema(description = "消息ID") String id){
        return Result.ok(userService.getMsgInfo(id));
    }

    /**
     * @Author SheepHy
     * @Description 场地列表查询
     * @Date 10:37 2025/7/4
     * @Param
     * @return
     **/
    @PostMapping("/getPlaceList")
    @Operation(summary = "场地列表查询 词典CODE：venue_type")
    public Result<Page<PlaceVO>> getPlaceList(@RequestBody(required = true) GetPlaceListDTO getPlaceListDTO){
        return Result.ok(appHomeService.getPlaceList(getPlaceListDTO));
    }

    /**
     * @Author SheepHy
     * @Description 全局搜索
     * @Date 10:37 2025/7/4
     * @Param
     * @return
     **/
    @PostMapping("/search")
    @Operation(summary = "全局搜索 词典CODE：search_type")
    public Result<Object> search(@RequestBody SearchDTO searchDTO){
        return Result.ok(appHomeService.search(searchDTO));
    }

    /**
     * @Author SheepHy
     * @Description 热词查询
     * @Date 17:12 2025/7/7
     * @return List<AppSearchHot>
     **/
    @GetMapping("/getHotSearch")
    @Operation(summary = "热词查询")
    public Result<List<AppSearchHot>> getHotSearch(){
        return Result.ok(appHomeService.getHotSearch());
    }

}
