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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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;

@Api(tags = {"角色邮件发送记录"})
@RestController
@RequestMapping("/role/mail/record")
@Slf4j
public class RoleMailController {

    @Autowired
    private IRoleMailRecordService roleMailRecordService;

    @ApiOperation(value = "邮件记录新增或者更新")
    @PostMapping(value = "/add/or/update")
    @PreAuthorize(permissionKey = "manage:roleMail:addOrUpdate")
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody RoleMailRecordAddParam param) {
        return ResultVO.ok(roleMailRecordService.addOrUpdate(param));
    }

    @ApiOperation(value = "邮件记录列表查询")
    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:roleMail:list")
    public ResultVO<IPage<RoleMailRecordListVO>> list(@Validated @RequestBody RoleMailRecordListParam param) {
        return ResultVO.ok(roleMailRecordService.listOfPage(param));
    }

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