package com.ruoyi.web.app;

import com.ruoyi.bst.article.domain.ArticleQuery;
import com.ruoyi.bst.article.domain.ArticleVO;
import com.ruoyi.bst.article.service.ArticleService;
import com.ruoyi.bst.articleCategory.domain.ArticleCategoryQuery;
import com.ruoyi.bst.articleCategory.domain.ArticleCategoryVO;
import com.ruoyi.bst.articleCategory.domain.enums.ArticleCategoryStatus;
import com.ruoyi.bst.articleCategory.domain.enums.ArticleCategoryType;
import com.ruoyi.bst.articleCategory.service.ArticleCategoryService;
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 io.swagger.annotations.ApiOperation;
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;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/app/articleCategory")
public class AppArticleCategoryController extends BaseController {

    @Autowired
    private ArticleCategoryService articleCategoryService;

    @Autowired
    private ArticleService articleService;


    @ApiOperation("查询所有文章分类信息")
    @GetMapping("/list")
    @Anonymous
    public TableDataInfo getArticleCategory(ArticleCategoryQuery articleCategoryQuery) {
        startPage();
        articleCategoryQuery.setCategoryStatus(ArticleCategoryStatus.ENABLED.getCode());
        return getDataTable(articleCategoryService.selectArticleCategoryList(articleCategoryQuery));
    }

    @ApiOperation("查询分类为商户帮助中心的分类信息")
    @GetMapping("/storeHelp/list")
    @Anonymous
    public TableDataInfo getStoreHelpArticle(ArticleCategoryQuery articleCategoryQuery) {
        startPage();
        //查询分类的文章
        articleCategoryQuery.setCategoryStatus(ArticleCategoryStatus.ENABLED.getCode());
        articleCategoryQuery.setType(ArticleCategoryType.STOREHELP.getCode());
        return getDataTable(articleCategoryService.selectArticleCategoryList(articleCategoryQuery));
    }

    @ApiOperation("查询分类下的文章")
    @GetMapping("/article")
    @Anonymous
    public TableDataInfo getArticle(ArticleCategoryQuery articleCategoryQuery) {
        startPage();
        //查询分类的文章
        ArticleQuery articleQuery = new ArticleQuery();
        articleQuery.setCategoryId(articleCategoryQuery.getId());
        List<ArticleVO> list = articleService.selectArticleList(articleQuery);
        return getDataTable(list);
    }

}
