package com.zhongshu.card.server.core.controller.attendance;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.attendance.ApplyLeaveParam;
import com.zhongshu.card.client.model.attendance.ApprovalLeaveParam;
import com.zhongshu.card.client.model.attendance.LeaveQueryParam;
import com.zhongshu.card.client.model.attendance.LeaveSettingParam;
import com.zhongshu.card.server.core.service.attendance.LeaveService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("leave")
@Tag(name = "请假")
public class LeaveController {

    @Autowired
    LeaveService leaveService;

    @Operation(summary = "请假应用场景配置", description = "数据详情")
    @RequestMapping(value = "setting", method = {RequestMethod.POST})
    @ResourceAuth(value = "user", type = AuthType.User)
    public ResultContent setting(@RequestBody @Valid LeaveSettingParam param){
        return leaveService.setting(param);
    }

    @Operation(summary = "获取请假应用场景配置", description = "数据详情")
    @RequestMapping(value = "getSetting", method = {RequestMethod.GET})
    @ResourceAuth(value = "user", type = AuthType.User)
    public ResultContent getSetting(@RequestParam("sceneId") String sceneId){
        return leaveService.getSetting(sceneId);
    }

    @Operation(summary = "发起请假申请", description = "发起请假申请")
    @RequestMapping(value = "apply", method = {RequestMethod.POST})
    @ResourceAuth(value = "user", type = AuthType.User)
    public ResultContent apply(@RequestBody @Valid ApplyLeaveParam param){
        return leaveService.apply(param);
    }

    @Operation(summary = "请假审批", description = "审批请假申请")
    @RequestMapping(value = "approval", method = {RequestMethod.POST})
    @ResourceAuth(value = "user", type = AuthType.User)
    public ResultContent approval(@RequestBody @Valid ApprovalLeaveParam param){
        return leaveService.approval(param);
    }

    @Operation(summary = "请假申请列表（分页）", description = "请假申请列表（分页）")
    @RequestMapping(value = "page", method = {RequestMethod.POST})
    @ResourceAuth(value = "user", type = AuthType.User)
    public ResultContent page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10)Pageable pageable,
                              @Parameter(required = false) LeaveQueryParam param){
        return leaveService.page(pageable,param);
    }

    @Operation(summary = "应用管理-请假申请列表（分页）", description = "应用管理-请假申请列表（分页）")
    @RequestMapping(value = "pageLeave", method = {RequestMethod.POST})
    @ResourceAuth(value = "user", type = AuthType.User)
    public ResultContent pageLeave(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10)Pageable pageable,
                              @Parameter(required = false) LeaveQueryParam param){
        return leaveService.pageLeave(pageable,param);
    }
}
