package com.zanxiang.game.module.manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.module.manage.pojo.params.*;
import com.zanxiang.game.module.manage.pojo.vo.GameGiftPackCodeLogVO;
import com.zanxiang.game.module.manage.pojo.vo.GameGiftPackCodeVO;
import com.zanxiang.game.module.manage.pojo.vo.GameGiftPackLinkLogVO;
import com.zanxiang.game.module.manage.pojo.vo.GameGiftPackLinkVO;
import com.zanxiang.game.module.manage.service.*;
import com.zanxiang.module.util.pojo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.util.function.Tuple2;

import java.util.List;
import java.util.Map;

/**
 * @author : lingfeng
 * @time : 2024-10-31
 * @description : 游戏发码器
 */
@Slf4j
@Api(tags = {"游戏发码器"})
@RestController
@RequestMapping("/game/gift/pack")
public class GameGiftPackController {

    @Autowired
    private IGameGiftPackCodeService gameGiftPackCodeService;

    @Autowired
    private IGameGiftPackLinkService gameGiftPackLinkService;

    @Autowired
    private IGameGiftPackConfigService gameGiftPackConfigService;

    @Autowired
    private IGameGiftPackLinkLogService gameGiftPackLinkLogService;

    @Autowired
    private IGameGiftPackCodeLogService gameGiftPackCodeLogService;

    @ApiOperation(value = "获取发码器配置")
    @GetMapping(value = "/config/list")
    @PreAuthorize(permissionKey = "manage:giftPack:configList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = List.class)})
    public ResultVO<List<Tuple2<Map<Long, String>, Map<String, String>>>> getGameGiftPackConfig() {
        return ResultVO.ok(gameGiftPackConfigService.getGameGiftPackConfig());
    }

    @ApiOperation(value = "查询礼包码链接列表")
    @PostMapping(value = "/link/list")
    @PreAuthorize(permissionKey = "manage:giftPack:linkList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameGiftPackLinkVO.class)})
    public ResultVO<IPage<GameGiftPackLinkVO>> linkList(@Validated @RequestBody GameGiftPackLinkListParam param) {
        return ResultVO.ok(gameGiftPackLinkService.list(param));
    }

    @ApiOperation(value = "更新礼包码链接")
    @PostMapping(value = "/link/update")
    @PreAuthorize(permissionKey = "manage:giftPack:linkUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> updateGiftPackLink(@Validated @RequestBody GameGiftPackLinkUpdateParam param) {
        return ResultVO.ok(gameGiftPackLinkService.updateGiftPackLink(param));
    }

    @ApiOperation(value = "删除礼包码链接")
    @DeleteMapping(value = "/link/delete")
    @PreAuthorize(permissionKey = "manage:giftPack:linkDelete")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> deleteById(@RequestParam Long id) {
        return ResultVO.ok(gameGiftPackLinkService.deleteById(id));
    }

    @ApiOperation(value = "添加礼包码链接")
    @PostMapping(value = "/link/add")
    @PreAuthorize(permissionKey = "manage:giftPack:linkAdd")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> addGiftPackLink(@Validated @RequestBody GameGiftPackLinkAddParam param) {
        return ResultVO.ok(gameGiftPackLinkService.addGiftPackLink(param));
    }

    @ApiOperation(value = "查询链接礼包码列表")
    @PostMapping(value = "/link/code/list")
    @PreAuthorize(permissionKey = "manage:giftPack:linkCodeList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameGiftPackCodeVO.class)})
    public ResultVO<IPage<GameGiftPackCodeVO>> linkList(@Validated @RequestBody GameGiftPackCodeListParam param) {
        return ResultVO.ok(gameGiftPackCodeService.list(param));
    }

    @ApiOperation(value = "添加链接礼包码")
    @PostMapping(value = "/link/code/add")
    @PreAuthorize(permissionKey = "manage:giftPack:linkCodeAdd")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> addGiftPackLin(@Validated @RequestBody GameGiftPackCodeAddParam param) {
        return ResultVO.ok(gameGiftPackCodeService.addGiftPackCode(param));
    }

    @ApiOperation(value = "更新链接礼包码")
    @PostMapping(value = "/link/code/update")
    @PreAuthorize(permissionKey = "manage:giftPack:linkCodeUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> updateGiftPackLin(@Validated @RequestBody GameGiftPackCodeUpdateParam param) {
        return ResultVO.ok(gameGiftPackCodeService.updateGiftPackCode(param));
    }

    @ApiOperation(value = "查询链接访问记录")
    @PostMapping(value = "/link/log/list")
    @PreAuthorize(permissionKey = "manage:giftPack:linkLogList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameGiftPackLinkLogVO.class)})
    public ResultVO<IPage<GameGiftPackLinkLogVO>> linkLogList(@Validated @RequestBody GameGiftPackLinkLogListParam param) {
        return ResultVO.ok(gameGiftPackLinkLogService.list(param));
    }

    @ApiOperation(value = "查询礼包码领取记录")
    @PostMapping(value = "/code/log/list")
    @PreAuthorize(permissionKey = "manage:giftPack:codeLogList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameGiftPackCodeLogVO.class)})
    public ResultVO<IPage<GameGiftPackCodeLogVO>> codeLogList(@Validated @RequestBody GameGiftPackCodeLogListParam param) {
        return ResultVO.ok(gameGiftPackCodeLogService.list(param));
    }
}
