package com.mcwl.web.controller.communityCenter;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mcwl.common.constant.HttpStatus;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.domain.R;
import com.mcwl.common.core.page.TableDataInfo;
import com.mcwl.communityCenter.domain.Publish;
import com.mcwl.communityCenter.domain.dto.*;
import com.mcwl.communityCenter.domain.vo.PublishVo;
import com.mcwl.communityCenter.service.PublishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Objects;

/**
 * 发布
 */
@Api(tags = "社区帖子发布")
@RestController
@RequestMapping("publish")
@RequiredArgsConstructor
public class PublishController {

    private final PublishService publishService;

    /**
     * 获取发布详情
     */
    @ApiOperation(value = "获取发布详情")
    @PostMapping("detail")
    public R<PublishVo> getPublishDetail(@RequestBody @Valid PublishDetailRes publishDetailRes) {

        PublishVo publishVo = publishService.getDetail(publishDetailRes);
        if (Objects.isNull(publishVo)) {
            return R.fail(HttpStatus.SHOW_ERROR_MSG, "获取详情失败");
        }
        return R.ok(publishVo);
    }

    /**
     * 添加
     */
    @ApiOperation(value = "发布")
    @PostMapping("publish")
    public R<Object> publish(@RequestBody @Valid PublishRes publishRes) {
        return publishService.publish(publishRes);
    }

    /**
     * 获取发布列表
     */
    @ApiOperation(value = "获取发布列表")
    @PostMapping("publishList")
    public TableDataInfo publishList(@RequestBody @Valid PublishPageRes publishPageRes) {
        return publishService.publishList(publishPageRes);
    }

//    /**
//     * 获取发布图片列表
//     */
//    @ApiOperation(value = "获取发布图片列表")
//    @PostMapping("publishImage")
//    public TableDataInfo publishImage(@RequestBody @Valid PublishPageRes publishPageRes) {
//        return publishService.publishImage(publishPageRes);
//    }
//
//    /**
//     * 获取发布文件列表
//     */
//    @ApiOperation(value = "获取发布文件列表")
//    @PostMapping("publishFile")
//    public TableDataInfo publishFile(@RequestBody @Valid PublishPageRes publishPageRes) {
//        return publishService.publishFile(publishPageRes);
//    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @PostMapping("remove")
    public R<Object> deletePublish(@RequestBody @Valid PublishRemoveRes publishRemoveRes) {

        return publishService.removePublish(publishRemoveRes);
    }

    /**
     * 精选/取消精选
     */
    @ApiOperation(value = "精选/取消精选")
    @GetMapping("elite")
    public R<Object> elitePublish(@NotNull(message = "租户id不能为空")
                                  @ApiParam(value = "租户id")
                                  @Valid Long tenantId,
                                  @NotNull(message = "社区id不能为空")
                                  @ApiParam(value = "社区id")
                                  @Valid Long communityId,
                                  @NotNull(message = "发布文章id不能为空")
                                  @ApiParam(value = "发布文章id")
                                  @Valid Long publishId) {

        return publishService.elitePublish(tenantId, communityId, publishId);
    }

    /**
     * 收藏/取消收藏
     */
    @ApiOperation(value = "收藏/取消收藏")
    @PostMapping("collect")
    public R<Object> collectPublish(@RequestBody @Valid PublishCollectRes publishCollectRes) {
        publishService.collectPublish(publishCollectRes);
        return R.ok();
    }

}
