package shop.alien.second.platform;

import com.baomidou.mybatisplus.core.metadata.IPage;
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.*;
import shop.alien.second.service.RiskControlService;

import java.util.List;

/**
 * 风控商品信息控制器
 */
@Slf4j
@Api(tags = {"二手平台-风控商品信息管理(管理后台)"})
@ApiSort(2)
@CrossOrigin
@RequiredArgsConstructor
@RestController
@RequestMapping("/riskControl")
public class PlatformRiskControlController {

    private final RiskControlService riskControlService;

    /**
     * 风控数据
     *
     * @param vo
     */
    @ApiOperation("风控数据")
    @PostMapping("/queryRiskControlRecords")
    public R<IPage<SecondRiskControlRecordVo>> queryRiskControlRecords(@RequestBody SecondRiskControlRecordVo vo) {
        return R.data(riskControlService.queryRiskControlRecords(vo));
    }


    @ApiOperation("风控数据")
    @PostMapping("/queryRiskControlRecordsDetail")
    public R<SecondRiskRecordVo> queryRiskControlRecordsDetail(@RequestBody SecondRiskRecordVo vo) throws Exception {
        return R.data(riskControlService.queryRiskControlRecordsDetail(vo));
    }

    @ApiOperation("账号封禁处理")
    @PostMapping("/accountBan")
    public R<SecondRiskRecordVo> accountBan(@RequestBody SecondRiskRecordVo vo) throws Exception {
        try {
            boolean type = riskControlService.accountBan(vo);
            if (!type) {
                return R.fail("封禁失败");
            }
            return R.success("封禁成功");
        } catch (Exception e) {
            return R.fail("系统异常，请联系管理员!!!");
        }
    }

}