package com.playlet.web.controller.app;

import com.github.pagehelper.PageInfo;
import com.playlet.common.core.domain.Result;
import com.playlet.system.domain.PlayletPublicDetail;
import com.playlet.web.service.app.PlayletPublicDetailAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "公众号*文章详情接口")
@RestController
@RequestMapping(value = "/app/detail")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlayletPublicDetailAppController {

    private final PlayletPublicDetailAppService playletPublicDetailAppService;

    /**
     * 分页查询任务列表
     */
    @ResponseBody
    @PostMapping("/getList")
    @ApiOperation(value = "分页查询文章列表")
    public Result<PageInfo<PlayletPublicDetail>> getList(@RequestBody PlayletPublicDetail playletPublicDetail,
                                                         @RequestParam(value = "pageNum") Integer pageNum,
                                                         @RequestParam(value = "pageSize") Integer pageSize) {
        playletPublicDetail.setType("01");
        playletPublicDetail.setTopStatus("01");
        return Result.success(playletPublicDetailAppService.getList(playletPublicDetail, pageNum, pageSize));
    }

    /**
     * 分页查询任务列表
     */
    @ResponseBody
    @PostMapping("/getTopList")
    @ApiOperation(value = "查询置顶文章列表")
    public Result<List<PlayletPublicDetail>> getTopList(@RequestBody PlayletPublicDetail playletPublicDetail) {
        playletPublicDetail.setType("01");
        playletPublicDetail.setTopStatus("02");
        return Result.success(playletPublicDetailAppService.getTopList(playletPublicDetail));
    }

    /**
     * 任务详情
     */
    @ResponseBody
    @GetMapping("/getById")
    @ApiOperation(value = "查询文章详情")
    public Result<PlayletPublicDetail> getById(@RequestParam(value = "id") Long id) {
        return Result.success(playletPublicDetailAppService.getById(id));
    }

    @ResponseBody
    @GetMapping("/getByIdNoContent")
    @ApiOperation(value = "查询文章详情,不含详情")
    public Result<PlayletPublicDetail> getByIdNoContent(@RequestParam(value = "id") Long id) {
        PlayletPublicDetail detail = playletPublicDetailAppService.getById(id);
        detail.setContent(null);
        return Result.success(detail);
    }

    @ResponseBody
    @GetMapping("/getByEncodeId")
    @ApiOperation(value = "查询文章详情")
    public Result<PlayletPublicDetail> getByEncodeId(@RequestParam(value = "id") Long id) {
        return Result.success(playletPublicDetailAppService.getById(id));
    }

    @ResponseBody
    @GetMapping("/getByEncodeIdNoContent")
    @ApiOperation(value = "查询文章详情,不含详情")
    public Result<PlayletPublicDetail> getByEncodeIdNoContent(@RequestParam(value = "id") Long id) {
        PlayletPublicDetail detail = playletPublicDetailAppService.getById(id);
        detail.setContent(null);
        return Result.success(detail);
    }

}
