package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.dto.StoreCommentAppealSupplementAddDto;
import shop.alien.entity.store.dto.StoreCommentAppealSupplementUpdateDto;
import shop.alien.entity.store.vo.StoreCommentAppealSupplementVo;
import shop.alien.store.service.StoreCommentAppealSupplementService;

import java.util.List;

/**
 * 评论申诉-用户补充内容 前端控制器
 */
@Slf4j
@Api(tags = {"二期-评论申诉用户补充"})
@ApiSort(13)
@CrossOrigin
@RestController
@RequestMapping("/storeCommentAppealSupplement")
@RequiredArgsConstructor
public class StoreCommentAppealSupplementController {

    private final StoreCommentAppealSupplementService supplementService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "用户端-新增申诉补充", notes = "result: 0成功 1失败 2申诉已结案 3文本异常 4无权限")
    @PostMapping("/add")
    public R<StoreCommentAppealSupplementVo> add(@RequestBody StoreCommentAppealSupplementAddDto dto) {
        log.info("StoreCommentAppealSupplementController.add?dto={}", dto);
        return supplementService.addSupplement(dto);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("用户端-修改申诉补充")
    @PostMapping("/update")
    public R<StoreCommentAppealSupplementVo> update(@RequestBody StoreCommentAppealSupplementUpdateDto dto) {
        log.info("StoreCommentAppealSupplementController.update?dto={}", dto);
        return supplementService.updateSupplement(dto);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("用户端-删除申诉补充")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "补充ID", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", paramType = "query", required = true)
    })
    @DeleteMapping("/delete")
    public R<Boolean> delete(@RequestParam Integer id, @RequestParam Long userId) {
        log.info("StoreCommentAppealSupplementController.delete?id={}&userId={}", id, userId);
        return supplementService.deleteSupplement(id, userId);
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("查询申诉补充详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "补充ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/detail")
    public R<StoreCommentAppealSupplementVo> detail(@RequestParam Integer id) {
        log.info("StoreCommentAppealSupplementController.detail?id={}", id);
        return R.data(supplementService.getDetail(id));
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("按申诉ID查询补充列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appealId", value = "申诉ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/listByAppealId")
    public R<List<StoreCommentAppealSupplementVo>> listByAppealId(@RequestParam Integer appealId) {
        log.info("StoreCommentAppealSupplementController.listByAppealId?appealId={}", appealId);
        return R.data(supplementService.listByAppealId(appealId));
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation("按评论ID查询补充列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "评论ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/listByCommentId")
    public R<List<StoreCommentAppealSupplementVo>> listByCommentId(@RequestParam Integer commentId) {
        log.info("StoreCommentAppealSupplementController.listByCommentId?commentId={}", commentId);
        return R.data(supplementService.listByCommentId(commentId));
    }

    @ApiOperationSupport(order = 7)
    @ApiOperation("分页查询申诉补充")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "页容", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "appealId", value = "申诉ID", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "storeId", value = "门店ID", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "auditStatus", value = "审核状态：0-待审核 1-通过 2-驳回", dataType = "Integer", paramType = "query")
    })
    @GetMapping("/page")
    public R<IPage<StoreCommentAppealSupplementVo>> page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) Integer appealId,
            @RequestParam(required = false) Long userId,
            @RequestParam(required = false) Integer storeId,
            @RequestParam(required = false) Integer auditStatus) {
        log.info("StoreCommentAppealSupplementController.page?pageNum={}&pageSize={}&appealId={}&userId={}&storeId={}&auditStatus={}",
                pageNum, pageSize, appealId, userId, storeId, auditStatus);
        return R.data(supplementService.getPage(pageNum, pageSize, appealId, userId, storeId, auditStatus));
    }
}
