package shop.alien.second.controller;

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.SecondReportingVo;
import shop.alien.entity.second.vo.SecondUserViolationVo;
import shop.alien.second.service.SecondGoodsReportingService;

@Slf4j
@Api(tags = {"二手平台-举报详情"})
@ApiSort(9)
@CrossOrigin
@RestController
@RequestMapping("/second/reporting")
@RequiredArgsConstructor
public class SecondGoodsReportingController {

    private final SecondGoodsReportingService service;

    @ApiOperation("举报详情")
    @PostMapping("/queryReportingDetail")
    public R<SecondReportingVo> queryReportingDetail(@RequestParam(value = "id", required = false) Integer id) {
        log.info("SecondGoodsReportingController.reportingDetail?id={}", id);
        return R.data(service.queryReportingDetail(id), "查询成功");
    }

    @ApiOperation("举报")
    @PostMapping("/addReport")
    public R<String> reporting(@RequestBody SecondUserViolationVo lifeuserViolation) throws Exception {
        log.info("SecondGoodsReportingController.reporting?lifeuserViolation={}", lifeuserViolation);
        int num = service.reporting(lifeuserViolation);
        if (0 == num) {
            return R.fail("举报失败");
        }
        return R.data("举报成功");
    }

}
