package cn.stylefeng.team.portal.modular.front.controller;

import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.team.portal.modular.front.pojo.request.CommonComponentRequest;
import cn.stylefeng.team.portal.modular.front.pojo.request.CommonPageRequest;
import cn.stylefeng.team.portal.modular.front.pojo.request.CommonSummaryRequest;
import cn.stylefeng.team.portal.modular.front.pojo.response.CommonSummaryItem;
import cn.stylefeng.team.portal.modular.front.service.ComponentNewsService;
import cn.stylefeng.team.portal.modular.management.entity.PortalNews;
import cn.stylefeng.team.portal.modular.management.entity.PortalNewsCategory;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@ApiResource(name = "新闻组件")
public class ComponentNewsController {

    @Resource
    private ComponentNewsService componentNewsService;

    @GetResource(name = "获取门户下的所有新闻分类", path = "/component/news/getCategoryList")
    public ResponseData<List<PortalNewsCategory>> getCategoryList(@Validated(CommonComponentRequest.list.class) CommonComponentRequest slideshowSelectListRequest) {
        List<PortalNewsCategory> list = componentNewsService.getCategoryList(slideshowSelectListRequest);
        return new SuccessResponseData<>(list);
    }

    @PostResource(name = "获取门户下的所有新闻分类", path = "/component/news/summary")
    public ResponseData<List<CommonSummaryItem>> summary(@RequestBody @Validated CommonSummaryRequest newsSummaryRequest) {
        List<CommonSummaryItem> list = componentNewsService.getNewsSummary(newsSummaryRequest);
        return new SuccessResponseData<>(list);
    }

    @GetResource(name = "首页渲染-新闻分页列表", path = "/component/news/pageList")
    public ResponseData<PageResult<PortalNews>> pageList(@Validated CommonPageRequest commonPageRequest) {
        return new SuccessResponseData<>(componentNewsService.getNewsPageList(commonPageRequest));
    }

    @GetResource(name = "首页渲染-获取文章详情", path = "/component/news/detail")
    public ResponseData<PortalNews> detail(@RequestParam("newsId") Long newsId) {
        return new SuccessResponseData<>(componentNewsService.getNewsDetail(newsId));
    }

}
