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.RoleGiftRecordAddParam;
import com.zanxiang.game.module.manage.pojo.params.RoleGiftRecordListParam;
import com.zanxiang.game.module.manage.pojo.vo.RoleGiftRecordListVO;
import com.zanxiang.game.module.manage.service.IRoleGiftRecordService;
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;

@RestController
@RequestMapping("/role/gift/record")
@Slf4j
public class RoleGiftController {

    @Autowired
    private IRoleGiftRecordService roleGiftRecordService;

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

    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:roleGift:list")
    public ResultVO<IPage<RoleGiftRecordListVO>> list(@Validated @RequestBody RoleGiftRecordListParam param) {
        return ResultVO.ok(roleGiftRecordService.listOfPage(param));
    }

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