package shop.alien.second.platform;

import com.alibaba.fastjson2.JSONObject;
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.second.vo.SecondTradeRecordVo;
import shop.alien.second.service.PlatformSecondTradeService;

import java.util.Date;
import java.util.List;

@Slf4j
@Api(tags = {"平台-二手交易记录"})
@ApiSort(1)
@CrossOrigin
@RequiredArgsConstructor
@RestController
@RequestMapping("/platformSecondTrade")
public class PlatformSecondTradeController {

    private final PlatformSecondTradeService secondTradeRecordService;

    @ApiOperation("交易列表(分页)")
    @ApiOperationSupport(order = 1)
    @PostMapping("/getTradeRecordPage")
    public R<IPage<SecondTradeRecordVo>> getTradeRecordPage(@RequestBody SecondTradeRecordVo vo) throws Exception {
        log.info("PlatformSecondTradeController.getTradeRecordPage?vo={}", vo.toString());
        return R.data(secondTradeRecordService.getTradeRecordPage(vo));
    }

    @ApiOperation("交易列表(不分页)")
    @ApiOperationSupport(order = 2)
    @GetMapping("/getTradeRecordList")
    public R<List<SecondTradeRecordVo>> getTradeRecordList(Integer userId, String beginTime, String endTime) throws Exception {
        log.info("PlatformSecondTradeController.getTradeRecordList?userId={},beginTime={},endTime={}", userId, beginTime, endTime);
        return R.data(secondTradeRecordService.getTradeRecordList(userId, beginTime, endTime));
    }

    @ApiOperation("交易详情")
    @ApiOperationSupport(order = 3)
    @GetMapping("/getTradeRecordById")
    public R<SecondTradeRecordVo> getTradeRecordById(Integer id) throws Exception {
        log.info("PlatformSecondTradeController.getTradeRecordById?id={}",id);
        return R.data(secondTradeRecordService.getTradeRecordById(id));
    }

    @ApiOperation("排行榜")
    @ApiOperationSupport(order = 4)
    @GetMapping("/getRankingList")
    public R<List<JSONObject>> getRankingList(String beginTime, String endTime) throws Exception {
        log.info("PlatformSecondTradeController.getRankingList");
        return R.data(secondTradeRecordService.getRankingList(beginTime, endTime));
    }

    @ApiOperation("交易失效")
    @ApiOperationSupport(order = 5)
    @GetMapping("/setTradeFailure")
    public R<Boolean> setTradeFailure(Integer tradeId, String failureReason) throws Exception {
        log.info("PlatformSecondTradeController.setTradeFailure?tradeId={},failureReason={}", tradeId, failureReason);
        secondTradeRecordService.setTradeFailure(tradeId, failureReason);
        return R.success("操作成功");
    }

    @ApiOperation("查询存在洗钱嫌疑的交易")
    @ApiOperationSupport(order = 6)
    @GetMapping("/getTradeRecordListByRiskId")
    public R<List<SecondTradeRecordVo>> getTradeRecordListByRiskId(Integer id) throws Exception {
        log.info("PlatformSecondTradeController.getTradeRecordListByRiskId?id={}", id);
        return R.data(secondTradeRecordService.getTradeRecordListByRiskId(id));
    }

    @ApiOperation("封禁账号取消交易")
    @ApiOperationSupport(order = 7)
    @GetMapping("/bannedAccountCancelTrade")
    public R<Boolean> bannedAccountCancelTrade(Integer userId) throws Exception {
        log.info("PlatformSecondTradeController.bannedAccountCancelTrade?userId={}", userId);
        secondTradeRecordService.bannedAccountCancelTrade(userId);
        return R.success("操作成功");
    }

}
