package com.ruoyi.web.controller.app;

import com.fasterxml.jackson.annotation.JsonView;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.JsonViewProfile;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.ss.article.domain.SmArticleQuery;
import com.ruoyi.ss.article.domain.enums.LicenceType;
import com.ruoyi.ss.article.domain.enums.SystemClassify;
import com.ruoyi.ss.article.service.ISmArticleService;
import com.ruoyi.ss.articleClassify.domain.SmArticleClassifyQuery;
import com.ruoyi.ss.articleClassify.service.ISmArticleClassifyService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wjh
 * 2024/4/3
 */
@RestController
@RequestMapping("/app/article")
public class AppArticleController extends BaseController {

    @Autowired
    private ISmArticleClassifyService articleClassifyService;

    @Autowired
    private ISmArticleService articleService;

    @ApiOperation("常见问题分类列表")
    @GetMapping("/problem/list")
    @JsonView(JsonViewProfile.App.class)
    public TableDataInfo getProblemList(SmArticleClassifyQuery dto) {
        startPage();
        dto.setParentId(SystemClassify.PROBLEM.getClassifyId());
        return getDataTable(articleClassifyService.selectClassifyList(dto));
    }

    @ApiOperation("获取文章列表")
    @GetMapping("/list")
    @JsonView(JsonViewProfile.App.class)
    public TableDataInfo getArticleList(SmArticleQuery dto) {
        startPage();
        return getDataTable(articleService.selectSmArticleList(dto));
    }

    @ApiOperation("获取文章详细内容")
    @GetMapping("/{articleId}")
    @JsonView(JsonViewProfile.App.class)
    public AjaxResult getDetail(@PathVariable Long articleId) {
        return success(articleService.selectSmArticleByArticleId(articleId));
    }

    @ApiOperation("获取协议文章")
    @GetMapping("/licence/{type}")
    @JsonView(JsonViewProfile.App.class)
    public AjaxResult getLicence(@PathVariable @ApiParam("协议类型") String type) {
        LicenceType licenceType = LicenceType.parse(type);
        return success(articleService.selectLicenceByType(licenceType));
    }

}
