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.RoleMailRecordAddParam;
import com.zanxiang.game.module.manage.pojo.params.RoleMailRecordListParam;
import com.zanxiang.game.module.manage.pojo.vo.RoleMailRecordListVO;
import com.zanxiang.game.module.manage.service.IRoleMailRecordService;
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/mail/record")
@Slf4j
public class RoleMailController {

    @Autowired
    private IRoleMailRecordService roleMailRecordService;

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

    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:roleMail:list")
    public ResultVO<IPage<RoleMailRecordListVO>> list(@Validated @RequestBody RoleMailRecordListParam param) {
        return ResultVO.ok(roleMailRecordService.listOfPage(param));
    }

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