package com.ruoyi.web.app;

import java.util.List;

import com.ruoyi.bst.help.service.HelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
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 com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.bst.help.domain.HelpQuery;
import com.ruoyi.bst.help.domain.HelpVO;
import com.ruoyi.bst.help.domain.enums.HelpStatus;
import com.ruoyi.bst.help.service.HelpService;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/app/help")
public class AppHelpController extends BaseController {

    @Autowired
    private HelpService helpService;

    @ApiOperation("获取教程列表")
    @GetMapping("list")
    @Anonymous
    public TableDataInfo list(HelpQuery query) {
        startPage();
        query.setStatus(HelpStatus.ENABLED.getCode());
        List<HelpVO> list = helpService.selectHelpList(query);
        return getDataTable(list);
    }

    @ApiOperation("获取教程详情")
    @GetMapping("/detail")
    @Anonymous
    public AjaxResult detail(@RequestParam(required = false) String code, @RequestParam(required = false) Long id) {
        if (StringUtils.hasText(code)) {
            return success(helpService.selectByCode(code));
        } else if (id != null) {
            return success(helpService.selectHelpById(id));
        }
        return success(null);
    }
}
