package jnpf.attendance.controller;

import com.github.pagehelper.PageInfo;
import jnpf.attendance.service.AttendanceFestivalRulesService;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.attendance.dto.AttendanceFestivalRulesDto;
import jnpf.model.attendance.dto.FestivalRulesQueryDto;
import jnpf.model.attendance.vo.attendance.AttendanceFestivalRulesVo;
import jnpf.util.FtbUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 节日规则
 *
 * @author 盼盼
 * @create 2025-09-18
 */
@RestController
@RequestMapping(value = "/attendance/festival-rules")
@Slf4j
public class AttendanceFestivalRulesController {

    @Autowired
    private AttendanceFestivalRulesService attendanceFestivalRulesService;


    /**
     * 获取考勤节日管理列表
     * @param queryDto 节日名称模糊查询非必传及年份筛选必传 
     */
    @PostMapping("/list")
    public ActionResult<PageListVO<AttendanceFestivalRulesVo>> list(@RequestBody FestivalRulesQueryDto queryDto) {
        PageInfo<AttendanceFestivalRulesVo> vo = attendanceFestivalRulesService.getPageList(queryDto);
        return ActionResult.page(vo.getList(), FtbUtil.getPagination(vo));
    }

    /**
     * 新增节日
     * @param festivalRulesDto 节日
     */
    @PostMapping()
    public ActionResult<Void> add(@RequestBody AttendanceFestivalRulesDto festivalRulesDto) throws Exception {
        attendanceFestivalRulesService.add(festivalRulesDto);
        return ActionResult.success();
    }

    /**
     * 更新法定节假日信息。
     *
     * @param year          年份
     * @return              处理结果视图对象
     */
    @PutMapping("statutoryUpdate")
    public ActionResult statutoryUpdate(@RequestParam String year) {
        attendanceFestivalRulesService.statutoryUpdate(year);
        return ActionResult.success();
    }
    /**
     * 修改节日
     * @param festivalRulesDto 节日
     */
    @PutMapping("/{id}")
    public ActionResult<Void> put(@PathVariable("id") String id, @RequestBody AttendanceFestivalRulesDto festivalRulesDto) throws Exception {
        festivalRulesDto.setId( id);
        attendanceFestivalRulesService.update(festivalRulesDto);
        return ActionResult.success();
    }

    /**
     * 获取节日详情
     * @param id 节日 ID
     */
    @GetMapping("/{id}")
    public ActionResult<AttendanceFestivalRulesVo> detail(@PathVariable("id") String id) {
        return ActionResult.success(attendanceFestivalRulesService.detail(id));
    }


    /**
     * 删除节日
     * @param id 节日 ID
     */
    @DeleteMapping("/{id}")
    public ActionResult<Void> delete(@PathVariable("id") String id) {
        attendanceFestivalRulesService.delete(id);
        return ActionResult.success();
    }

    /**
     * 启用、停用节日
     * @param festivalRulesDto 节日
     */
    @PutMapping("/updateState")
    public ActionResult<Void> updateState( @RequestBody AttendanceFestivalRulesDto festivalRulesDto) {
        attendanceFestivalRulesService.updateState(festivalRulesDto);
        return ActionResult.success();
    }

}
