package jnpf.attendance.controller;


import jnpf.attendance.service.AttendanceUserBalanceService;
import jnpf.base.ActionResult;
import jnpf.exception.HandleException;
import jnpf.model.attendance.dto.AttendanceUserBalanceDto;
import jnpf.model.attendance.dto.AttendanceUserBalanceListQueryDto;
import jnpf.model.attendance.vo.attendance.AttendanceUserBalanceListVo;
import jnpf.model.attendance.vo.attendance.AttendanceUserBalanceVo;
import jnpf.model.attendance.vo.attendance.AttendanceUserTitleVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 用户余额
 * @author 盼盼
 * @create 2025-09-18
 */
@RestController
@RequestMapping(value = "/attendance/user-balance")
@Slf4j
public class AttendanceUserBalanceController {

    @Autowired
    private AttendanceUserBalanceService attendanceUserBalanceService;

    /**
     * 获取考勤余额管理列表
     * @param queryDto 余额名称模糊查询非必传
     */
    @PostMapping("/list")
    public ActionResult<AttendanceUserBalanceListVo> list(@RequestBody @Valid AttendanceUserBalanceListQueryDto queryDto) throws HandleException {
        AttendanceUserBalanceListVo vo = attendanceUserBalanceService.list(queryDto);
        return ActionResult.success(vo);
    }

    /**
     * 编辑、批量编辑余额
     * @param userBalanceDto 余额
     */
    @PutMapping()
    public ActionResult<Void> updateUserBalance(@RequestBody AttendanceUserBalanceDto userBalanceDto) {
        attendanceUserBalanceService.updateUserBalance(userBalanceDto);
        return ActionResult.success();
    }

    /**
     * 获取余额详情
     * @param userBalanceDto 用户Id及类型Id（类型Id没有默认查调休）
     */
    @GetMapping("/detail")
    public ActionResult<AttendanceUserBalanceVo> getDetail(AttendanceUserBalanceDto userBalanceDto) {
        return ActionResult.success(attendanceUserBalanceService.getDetail(userBalanceDto));
    }

    /**
     * 获取余额详情页-顶部用户相关及动态假期表头
     * @param userBalanceDto 用户Id及类型Id（类型Id没有默认查调休）
     */
    @GetMapping("/title")
    public ActionResult<AttendanceUserTitleVo> getTitle(AttendanceUserBalanceDto userBalanceDto) {
        return ActionResult.success(attendanceUserBalanceService.getTitle(userBalanceDto));
    }


}
