package com.zanxiang.game.back.serve.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.back.serve.pojo.dto.GameOceanengineOrderLogDTO;
import com.zanxiang.game.back.serve.pojo.dto.GameOceanengineUserLogDTO;
import com.zanxiang.game.back.serve.pojo.vo.GameOceanengineOrderLogVO;
import com.zanxiang.game.back.serve.pojo.vo.GameOceanengineUserLogVO;
import com.zanxiang.game.back.serve.service.IGameOceanengineOrderLogService;
import com.zanxiang.game.back.serve.service.IGameOceanengineUserLogService;
import com.zanxiang.module.util.NumberUtil;
import com.zanxiang.module.util.exception.BaseException;
import com.zanxiang.module.util.pojo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/oceanengine")
@Api("回传策略")
public class OceanengineLogController {
    @Autowired
    private IGameOceanengineOrderLogService oceanengineOrderLogService;
    @Autowired
    private IGameOceanengineUserLogService oceanengineUserLogService;

    @PreAuthorize(permissionKey = "gameBack:oceanengine:orderLogs")
    @PostMapping("/orderLogs")
    @ApiOperation(value = "头条订单回传日志列表")
    public ResultVO<IPage<GameOceanengineOrderLogVO>> oceanengineOrderLogList(@RequestBody GameOceanengineOrderLogDTO dto) {
        return ResultVO.ok(oceanengineOrderLogService.oceanengineOrderLogList(dto));
    }

    @PreAuthorize(permissionKey = "gameBack:oceanengine:orderReport")
    @PostMapping("/orderReport/{ids}/{backMoney}")
    @ApiOperation(value = "头条订单手动上报")
    public ResultVO<Boolean> oceanengineOrderReport(@PathVariable("ids") List<Long> ids, @PathVariable("backMoney") BigDecimal backMoney) {
        if (backMoney.compareTo(BigDecimal.ZERO) <= 0) {
            throw new BaseException("回传金额错误！");
        }
        return ResultVO.ok(oceanengineOrderLogService.oceanengineOrderReport(ids, NumberUtil.multiply100(backMoney).longValue()));
    }

    @PreAuthorize(permissionKey = "gameBack:oceanengine:userLogs")
    @PostMapping("/userLogs")
    @ApiOperation(value = "头条用户回传日志列表")
    public ResultVO<IPage<GameOceanengineUserLogVO>> oceanengineUserLogList(@RequestBody GameOceanengineUserLogDTO dto) {
        return ResultVO.ok(oceanengineUserLogService.oceanengineUserLogList(dto));
    }

    @PreAuthorize(permissionKey = "gameBack:oceanengine:userReport")
    @PostMapping("/userReport/{ids}")
    @ApiOperation(value = "头条用户手动上报")
    public ResultVO<Boolean> oceanengineUserReport(@PathVariable("ids") List<Long> ids) {
        return ResultVO.ok(oceanengineUserLogService.oceanengineUserReport(ids));
    }
}
