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.GameGiftAddParam;
import com.zanxiang.game.module.manage.pojo.params.GameGiftListParam;
import com.zanxiang.game.module.manage.pojo.vo.GameGiftListVO;
import com.zanxiang.game.module.manage.service.IGameGiftService;
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 java.util.List;

/**
 * @author shishaosong
 */
@RestController
@RequestMapping("/game/gift")
@Slf4j
public class GameGiftController {

    @Autowired
    private IGameGiftService gameGiftService;

    @PostMapping(value = "/add/or/update")
    @PreAuthorize(permissionKey = "manage:gameGift:addOrUpdate")
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody GameGiftAddParam param) {
        return ResultVO.ok(gameGiftService.addOrUpdate(param));
    }

    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:gameGift:list")
    public ResultVO<List<GameGiftListVO>> list(@RequestBody GameGiftListParam param) {
        return ResultVO.ok(gameGiftService.queryAll(param));
    }

    @PostMapping(value = "/listOfPage")
    @PreAuthorize(permissionKey = "manage:gameGift:listOfPage")
    public ResultVO<IPage<GameGiftListVO>> listOfPage(@RequestBody GameGiftListParam param) {
        return ResultVO.ok(gameGiftService.listOfPage(param));
    }

    @DeleteMapping(value = "/delete/{ids}")
    @PreAuthorize(permissionKey = "manage:gameGift:delete")
    public ResultVO<Boolean> deleteById(@PathVariable("ids") Long ids) {
        return ResultVO.ok(gameGiftService.deleteByIds(ids));
    }
}
