package jnpf.attendance.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import jnpf.attendance.service.AttendanceFestivalSettingService;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.exception.HandleException;
import jnpf.model.attendance.dto.AttendanceFestivalSettingDto;
import jnpf.model.attendance.dto.EnableUpdateDto;
import jnpf.model.attendance.vo.AttendanceFestivalSettingVo;
import jnpf.model.attendance.vo.HolidayOptionVo;
import jnpf.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 考勤配置-节日配置 前端控制器
 * </p>
 *
 * @author ahua
 * @since 2023-11-29
 */
@RestController
@RequestMapping("/festival/setting")
public class AttendanceFestivalSettingController {
    @Autowired
    private AttendanceFestivalSettingService attendanceFestivalSettingService;
    /**
     * 保存节假日设置信息。
     *
     * @param attendanceFestivalSettingDto 节假日设置数据传输对象
     * @throws HandleException            处理异常
     * @return 处理结果视图对象
     */
    @PostMapping
    public ActionResult save(@RequestBody AttendanceFestivalSettingDto attendanceFestivalSettingDto) throws HandleException {
        attendanceFestivalSettingService.save(attendanceFestivalSettingDto);
        return ActionResult.success();
    }

    /**
     * 分页查询节假日设置信息。
     *
     * @param groupId        考勤组ID
     * @param year           年份（可选）
     * @param currentPage    当前页码
     * @param pageSize       每页大小
     * @return              分页的节假日设置视图对象列表
     * @throws HandleException 处理异常
     */
    @GetMapping
    public ActionResult<PageListVO<AttendanceFestivalSettingVo>> page(@RequestParam String groupId, @RequestParam(required = false) String year, @RequestParam Integer currentPage, @RequestParam Integer pageSize) throws HandleException {
        PageDTO<AttendanceFestivalSettingVo> page1 = attendanceFestivalSettingService.page(groupId, year, currentPage, pageSize);
        return ActionResult.page(page1.getRecords(), PageUtil.page(page1));
    }

    /**
     * 根据ID获取单个节假日设置信息。
     *
     * @param id 节假日设置ID
     * @return 节假日设置视图对象
     */
    @GetMapping("{id}")
    public ActionResult<AttendanceFestivalSettingVo> getOne(@PathVariable String id) {
        return ActionResult.success(attendanceFestivalSettingService.getOne(id));
    }

    /**
     * 删除指定的节假日设置信息。
     *
     * @param id 节假日设置ID
     * @return 处理结果视图对象
     */
    @DeleteMapping("{id}")
    public ActionResult del(@PathVariable String id) {
        attendanceFestivalSettingService.del(id);
        return ActionResult.success();
    }

    /**
     * 更改节假日设置信息的启用状态。
     *
     * @param enableUpdateDto 启用状态更新数据传输对象
     * @throws HandleException 处理异常
     * @return 处理结果视图对象
     */
    @PutMapping("updateStatus")
    public ActionResult updateStatus(@RequestBody EnableUpdateDto enableUpdateDto) throws HandleException {
        attendanceFestivalSettingService.updateStatus(enableUpdateDto.getId(), enableUpdateDto.getEnable());
        return ActionResult.success();
    }

    /**
     * 更新法定节假日信息。
     *
     * @param groupId       考勤组ID
     * @param year          年份
     * @return              处理结果视图对象
     */
    @PutMapping("statutoryUpdate")
    public ActionResult statutoryUpdate(@RequestParam String groupId, @RequestParam String year) {
        attendanceFestivalSettingService.statutoryUpdate(groupId, year);
        return ActionResult.success();
    }

    /**
     * 获取节假日选项列表。
     *
     * @param groupId 考勤组ID
     * @return 节假日选项视图对象列表
     */
    @GetMapping("options")
    public ActionResult<List<HolidayOptionVo>> getHolidayOptions(@RequestParam String groupId) {
        return ActionResult.success(attendanceFestivalSettingService.getHolidayOptions(groupId));
    }

}

