package jnpf.attendance.controller;

import com.github.pagehelper.PageInfo;
import jnpf.attendance.service.AttendanceShiftNameSettingService;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.exception.HandleException;
import jnpf.model.attendance.dto.FixedClassChangeStatusDto;
import jnpf.model.attendance.dto.FixedClassGroupDto;
import jnpf.model.attendance.dto.ShiftNameDto;
import jnpf.model.attendance.dto.ShiftNameQueryDto;
import jnpf.model.attendance.vo.attendance.ShiftNameListVo;
import jnpf.model.attendance.vo.attendance.ShiftNameVo;
import jnpf.util.FtbUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 考勤组配置-考勤班制 前端控制器
 * @Author huanglinpan
 * @Date 2024/5/9 10:01
 * @Version 1.0 （版本号）
 */
@RestController
@RequestMapping("/shifts/shiftName")
public class AttendanceShiftNameSettingController {

    @Resource
    private AttendanceShiftNameSettingService attendanceShiftNameSettingService;

    /**
     * 新增/修改班次名称
     * @param dto 班次名称信息
     */
    @PostMapping
    public ActionResult save(@RequestBody @Valid ShiftNameDto dto) throws HandleException {
        return attendanceShiftNameSettingService.save(dto);
    }

    /**
     * 起停班次
     * @param statusDto 班次状态修改dto
     */
    @PutMapping("/changeStatus")
    public ActionResult changeStatus(@RequestBody FixedClassChangeStatusDto statusDto) {
        return attendanceShiftNameSettingService.changeStatus(statusDto.getShiftNameId(), statusDto.getEnable(), statusDto.getUpdateShift());
    }

    /**
     * 删除班次
     * @param shiftNameId 班次名称Id
     */
    @DeleteMapping("/{shiftNameId}")
    public ActionResult delete(@PathVariable("shiftNameId") String shiftNameId) {
        return attendanceShiftNameSettingService.delete(shiftNameId);
    }

    /**
     * 获取班次详情
     * @param shiftNameId 班次名称Id
     */
    @GetMapping("{shiftNameId}")
    public ActionResult<ShiftNameVo> getDetail(@PathVariable("shiftNameId") String shiftNameId) {
        return ActionResult.success(attendanceShiftNameSettingService.getDetail(shiftNameId));
    }

    /**
     * 班次列表
     * @param queryDto 查询条件
     * @return
     */
    @GetMapping("/list")
    public ActionResult<PageListVO<ShiftNameListVo>> getList(@Valid ShiftNameQueryDto queryDto) throws HandleException {
        PageInfo<ShiftNameListVo> list = attendanceShiftNameSettingService.getList(queryDto);
        return ActionResult.page(list.getList(), FtbUtil.getPagination(list));
    }

    /**
     * 保存考勤组固定排班
     * @param dto 固定排班对象
     */
    @PutMapping("/fixedClass")
    public ActionResult saveOrUpdateFixedClass(@RequestBody @Valid FixedClassGroupDto dto) {
        return attendanceShiftNameSettingService.saveOrUpdateFixedClass(dto);
    }
}
