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

import com.github.microservice.net.ResultContent;
import com.github.microservice.staticVariable.OpenApiMark;
import com.zhongshu.card.client.model.attendance.LeaveApprovalModel;
import com.zhongshu.card.client.openApi.params.AddLeaveOpenApiParam;
import com.zhongshu.card.client.openApi.params.PageLeaveOpenApiParam;
import com.zhongshu.card.server.core.domain.attendance.LeaveApproval;
import com.zhongshu.card.server.core.service.openAPI.attendance.LeaveOpenApiService;
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.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/"+ OpenApiMark.fullCardOpenAPI +"/v1/leaveApproval")
@Tag(name = "openAPI-请假管理")
public class LeaveOpenApiController {

    @Autowired
    private LeaveOpenApiService leaveOpenApiService;

    @Operation(summary = "添加请假审批", description = "添加请假审批")
    @RequestMapping(value = "add", method = {RequestMethod.POST})
    public ResultContent<String> add(@RequestBody AddLeaveOpenApiParam param){
        return leaveOpenApiService.add(param);
    }

    @Operation(summary = "修改请假审批", description = "修改请假审批")
    @RequestMapping(value = "update", method = {RequestMethod.POST})
    public ResultContent<String> update(@RequestBody LeaveApproval param){
        return leaveOpenApiService.update(param);
    }

    @Operation(summary = "删除请假审批", description = "根据id删除请假审批")
    @RequestMapping(value = "delete", method = {RequestMethod.GET})
    public ResultContent delete(@RequestParam("id") String id){
        return leaveOpenApiService.delete(id);
    }

    @Operation(summary = "查询请假审批", description = "根据id查询请假审批")
    @RequestMapping(value = "findOneById", method = {RequestMethod.GET})
    public ResultContent<LeaveApprovalModel> findOneById(@RequestParam("id")String id){
        return leaveOpenApiService.findOneById(id);
    }

    @Operation(summary = "分页查询请假审批", description = "分页查询请假审批")
    @RequestMapping(value = "page", method = {RequestMethod.POST})
    public ResultContent<Page<LeaveApprovalModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10)Pageable pageable,
                                                        @Parameter(required = false) PageLeaveOpenApiParam param){
        return leaveOpenApiService.page(pageable,param);
    }
}
