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 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
@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;

    @GetMapping(value = "/config/list")
    @PreAuthorize(permissionKey = "manage:giftPack:configList")
    public ResultVO<List<Tuple2<Map<Long, String>, Map<String, String>>>> getGameGiftPackConfig() {
        return ResultVO.ok(gameGiftPackConfigService.getGameGiftPackConfig());
    }

    @PostMapping(value = "/link/list")
    @PreAuthorize(permissionKey = "manage:giftPack:linkList")
    public ResultVO<IPage<GameGiftPackLinkVO>> linkList(@Validated @RequestBody GameGiftPackLinkListParam param) {
        return ResultVO.ok(gameGiftPackLinkService.list(param));
    }

    @PostMapping(value = "/link/update")
    @PreAuthorize(permissionKey = "manage:giftPack:linkUpdate")
    public ResultVO<Boolean> updateGiftPackLink(@Validated @RequestBody GameGiftPackLinkUpdateParam param) {
        return ResultVO.ok(gameGiftPackLinkService.updateGiftPackLink(param));
    }

    @DeleteMapping(value = "/link/delete")
    @PreAuthorize(permissionKey = "manage:giftPack:linkDelete")
    public ResultVO<Boolean> deleteById(@RequestParam Long id) {
        return ResultVO.ok(gameGiftPackLinkService.deleteById(id));
    }

    @PostMapping(value = "/link/add")
    @PreAuthorize(permissionKey = "manage:giftPack:linkAdd")
    public ResultVO<Boolean> addGiftPackLink(@Validated @RequestBody GameGiftPackLinkAddParam param) {
        return ResultVO.ok(gameGiftPackLinkService.addGiftPackLink(param));
    }

    @PostMapping(value = "/link/code/list")
    @PreAuthorize(permissionKey = "manage:giftPack:linkCodeList")
    public ResultVO<IPage<GameGiftPackCodeVO>> linkList(@Validated @RequestBody GameGiftPackCodeListParam param) {
        return ResultVO.ok(gameGiftPackCodeService.list(param));
    }

    @PostMapping(value = "/link/code/add")
    @PreAuthorize(permissionKey = "manage:giftPack:linkCodeAdd")
    public ResultVO<Boolean> addGiftPackLin(@Validated @RequestBody GameGiftPackCodeAddParam param) {
        return ResultVO.ok(gameGiftPackCodeService.addGiftPackCode(param));
    }

    @PostMapping(value = "/link/code/update")
    @PreAuthorize(permissionKey = "manage:giftPack:linkCodeUpdate")
    public ResultVO<Boolean> updateGiftPackLin(@Validated @RequestBody GameGiftPackCodeUpdateParam param) {
        return ResultVO.ok(gameGiftPackCodeService.updateGiftPackCode(param));
    }

    @PostMapping(value = "/link/log/list")
    @PreAuthorize(permissionKey = "manage:giftPack:linkLogList")
    public ResultVO<IPage<GameGiftPackLinkLogVO>> linkLogList(@Validated @RequestBody GameGiftPackLinkLogListParam param) {
        return ResultVO.ok(gameGiftPackLinkLogService.list(param));
    }

    @PostMapping(value = "/code/log/list")
    @PreAuthorize(permissionKey = "manage:giftPack:codeLogList")
    public ResultVO<IPage<GameGiftPackCodeLogVO>> codeLogList(@Validated @RequestBody GameGiftPackCodeLogListParam param) {
        return ResultVO.ok(gameGiftPackCodeLogService.list(param));
    }
}
