package com.yida.data.school.userLeave.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vdurmont.emoji.EmojiManager;
import com.yida.data.common.core.annotation.ControllerLog;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.leave.EduLeaveRequest;
import com.yida.data.common.core.entity.userLeave.EduLeaveRequestProcessConfig;
import com.yida.data.common.core.entity.userLeave.EduLeaveRequestUser;
import com.yida.data.school.dto.userLeave.EduLeaveRequestProcessConfigDTO;
import com.yida.data.school.userLeave.service.EduLeaveRequestProcessConfigService;
import com.yida.data.school.vo.userLeave.EduLeaveRequestProcessConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Controller
 *
 * @author wjm
 * @date 2022-12-01 10:45:56
 */
@Slf4j
@Validated
@RestController
@RequestMapping("eduLeaveRequestProcessConfig")
@RequiredArgsConstructor
@Api(tags = "请假管理")
public class EduLeaveRequestProcessConfigController {

    private final EduLeaveRequestProcessConfigService eduLeaveRequestProcessConfigService;


    @ApiOperation("查询策略列表")
    @GetMapping("findPageList")
    public ResultBean<Page<EduLeaveRequestProcessConfigVO>> findPageList(
        @RequestParam(required = false) @ApiParam("策略名称") String processName,
        @RequestParam(required = true) @ApiParam("所属学校ID") Long schoolId,
        @RequestParam(defaultValue = "1") Long pageNum,
        @RequestParam(defaultValue = "10") Long pageSize) {
        Page<EduLeaveRequestProcessConfig> page = new Page<>();
        page.setSize(pageSize);
        page.setCurrent(pageNum);
        return ResultBean.buildSuccess(eduLeaveRequestProcessConfigService.findPageList(page, processName, schoolId));
    }

    @ApiOperation("新增/编辑请假策略")
    @PostMapping("add")
    public ResultBean add(@RequestBody EduLeaveRequestProcessConfigDTO dto) {
        eduLeaveRequestProcessConfigService.add(dto);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("批量删除请假策略")
    @PostMapping("/delBatch")
    public ResultBean deleteBatch(@RequestBody List<Long> ids) {
        eduLeaveRequestProcessConfigService.deleteBatch(ids);
        return ResultBean.buildSuccess();
    }

}
