package shop.alien.second.platform;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiSort;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.second.vo.SecondUserViolationDetailVo;
import shop.alien.entity.second.vo.SecondUserViolationVo;
import shop.alien.entity.store.LifeUserViolation;
import shop.alien.second.service.PlatformUserViolationService;

/**
 * 作者：邹建宇
 * 描述：
 */
@Slf4j
@Api(tags = {"平台-二手举报管理"})
@ApiSort(1)
@CrossOrigin
@RequiredArgsConstructor
@RestController
@RequestMapping("/platformUserViolation")
public class PlatformUserViolationController {

    private final PlatformUserViolationService service;

    @ApiOperation("查询举报信息")
    @PostMapping("/queryUserViolationByPage")
    public R<IPage<SecondUserViolationVo>> queryUserViolationByPage(@RequestBody SecondUserViolationVo vo) throws Exception {
        log.info("PlatformUserViolationController.queryUserViolationByPage");
        IPage<SecondUserViolationVo> page = new Page<>(vo.getPageNum(), vo.getPageSize());
        return R.data(service.getUserViolationByPage(page, vo.getReportingUserName(), vo.getReportingDate(), vo.getProcessingStatus(), vo.getReportContextType()), "查询成功");
    }


    @ApiOperation("查询举报详情")
    @GetMapping("/queryUserViolationDetail")
    public R<SecondUserViolationDetailVo> queryUserViolationDetail(Integer id) throws Exception {
        log.info("PlatformUserViolationController.queryUserViolationDetail");
        return R.data(service.getUserViolationDetail(id), "查询成功");
    }

    @ApiOperation("举报审核")
    @PostMapping("/updateUserViolation")
    public R<String> updateUserViolation(@RequestBody LifeUserViolation row) throws Exception {
        log.info("PlatformUserViolationController.queryUserViolationDetail");
        int num = service.updateUserViolation(row);
        if(num > 0) return R.success("审核成功");
        return R.fail("审核失败");
    }

}
