package cn.iocoder.yudao.module.system.controller.admin.holiday.holidayuserrecord;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.holiday.holidayuserrecord.vo.HolidayUserRecordPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.holiday.holidayuserrecord.vo.HolidayUserRecordRespVO;
import cn.iocoder.yudao.module.system.controller.admin.holiday.holidayuserrecord.vo.HolidayUserRecordSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.holiday.holidayuserrecord.HolidayUserRecordDO;
import cn.iocoder.yudao.module.system.service.holiday.holidayuserrecord.HolidayUserRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 员工假期记录")
@RestController
@RequestMapping("/system/holiday-user-record")
@Validated
public class HolidayUserRecordController {

    @Resource
    private HolidayUserRecordService holidayUserRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建员工假期记录")
    @PreAuthorize("@ss.hasPermission('system:holiday-user-record:create')")
    public CommonResult createHolidayUserRecord(@Valid @RequestBody HolidayUserRecordSaveReqVO createReqVO) {
        holidayUserRecordService.createHolidayUserRecord(createReqVO);
        return success("ok");
    }

    @GetMapping("/get")
    @Operation(summary = "获得员工假期记录")
    public CommonResult<List<HolidayUserRecordRespVO>> getHolidayUserRecord(@RequestParam("userId") Long userId,
                                                                            @RequestParam("holidaySettingId") Long holidaySettingId) {
        List<HolidayUserRecordDO> holidayUserRecord = holidayUserRecordService.getHolidayUserRecord(userId, holidaySettingId);
        return success(BeanUtils.toBean(holidayUserRecord, HolidayUserRecordRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得员工假期记录分页")
    @PreAuthorize("@ss.hasPermission('system:holiday-user-record:query')")
    public CommonResult<PageResult<HolidayUserRecordRespVO>> getHolidayUserRecordPage(@Valid HolidayUserRecordPageReqVO pageReqVO) {
        PageResult<HolidayUserRecordDO> pageResult = holidayUserRecordService.getHolidayUserRecordPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, HolidayUserRecordRespVO.class));
    }

}
