package com.xindazhou.business.controller.app.community.collect;

import com.xindazhou.business.controller.app.community.collect.vo.CollectPageReqVO;
import com.xindazhou.business.controller.app.community.post.vo.PostRespVO;
import com.xindazhou.business.service.community.collect.CollectService;
import com.xindazhou.framework.common.pojo.CommonResult;
import com.xindazhou.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.xindazhou.framework.common.pojo.CommonResult.success;

/**
 * 移动端 - 收藏 Controller
 *
 * @author xindazhou
 */
@Tag(name = "移动端 - 收藏管理")
@RestController
@RequestMapping("/app-api/community/collect")
@Validated
@Slf4j
public class CollectController {

    @Resource
    private CollectService collectService;

    @PostMapping("/toggle")
    @Operation(summary = "收藏/取消收藏")
    @Parameter(name = "postId", description = "帖子ID", required = true, example = "1")
    public CommonResult<Boolean> toggleCollect(@RequestParam("postId") Long postId) {
        Boolean isCollected = collectService.toggleCollect(postId);
        return success(isCollected);
    }

    @GetMapping("/check")
    @Operation(summary = "查询是否已收藏")
    @Parameter(name = "postId", description = "帖子ID", required = true, example = "1")
    public CommonResult<Boolean> isCollected(@RequestParam("postId") Long postId) {
        Boolean isCollected = collectService.isCollected(postId);
        return success(isCollected);
    }

    @GetMapping("/page")
    @Operation(summary = "获得收藏的帖子分页列表")
    public CommonResult<PageResult<PostRespVO>> getCollectPage(@Valid CollectPageReqVO pageReqVO) {
        PageResult<PostRespVO> pageResult = collectService.getCollectPage(pageReqVO);
        return success(pageResult);
    }

}

