package com.yuchen.saas.park.service.controller.fire.fight;

import com.thinkunion.park.service.common.constant.GroupAction;
import com.yuchen.saas.park.api.dto.fire.fight.FireFightDutyRecordsReqDTO;
import com.yuchen.saas.park.api.dto.fire.fight.FireFightShiftPlanReqDTO;
import com.yuchen.saas.park.api.dto.fire.fight.FireFightShiftPlanSubmitReqDTO;
import com.yuchen.saas.park.api.vo.fire.fight.FireFightDutyRecordsVO;
import com.yuchen.saas.park.api.vo.fire.fight.FireFightShiftDutyInfoVO;
import com.yuchen.saas.park.api.vo.fire.fight.FireFightShiftPlanVO;
import com.yuchen.saas.park.service.service.fire.fight.ISaasParkFireFightDutyRecordsService;
import com.yuchen.saas.park.service.service.fire.fight.ISaasParkFireFightShiftPlanService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.log.exception.ServiceException;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.secure.ContextUser;
import org.nest.springwrap.core.secure.utils.AuthUtil;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 消防排班-相关接口
 *
 * @author zhouhanwei
 * @since 2024-04-29
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/fightShiftPlan")
public class SaasParkFireFightShiftPlanController {

    private final ISaasParkFireFightShiftPlanService fightShiftPlanService;

    private final ISaasParkFireFightDutyRecordsService fireFightDutyRecordsService;

    /**
     * 消防排班计划列表
     */
    @PostMapping("/findFireFightShiftPlanList")
    @ApiOperation(value = "消防排班计划列表", notes = "消防排班计划列表")
    public R<List<FireFightShiftPlanVO>> findFireFightShiftPlanList(@RequestBody FireFightShiftPlanReqDTO reqDTO) {
        ContextUser contextUser = AuthUtil.getUser();
        if (Objects.isNull(contextUser)) {
            throw new ServiceException("用户不存在");
        }
        reqDTO.setCustomerId(contextUser.getCustomerManageId());
        return R.data(fightShiftPlanService.findFireFightShiftPlanList(reqDTO));
    }

    /**
     * 消防排班计划详情
     */
    @GetMapping("/getFireFightShiftPlan/{shiftPlanId}")
    @ApiOperation(value = "消防排班计划详情", notes = "消防排班计划详情")
    public R<FireFightShiftPlanVO> getFireFightShiftPlan(@PathVariable Long shiftPlanId) {
        return R.data(fightShiftPlanService.getFireFightShiftPlan(shiftPlanId));
    }

    /**
     * 添加消防排班计划
     */
    @PostMapping("/addFireFightShiftPlan")
    @ApiOperation(value = "添加消防排班计划", notes = "添加消防排班计划")
    public R addFireFightShiftPlan(@Validated(GroupAction.InsertAction.class) @RequestBody FireFightShiftPlanSubmitReqDTO reqDTO) {
        return R.status(fightShiftPlanService.addFireFightShiftPlan(reqDTO));
    }

    /**
     * 编辑消防排班计划
     */
    @PostMapping("/editFireFightShiftPlan")
    @ApiOperation(value = "编辑消防排班计划", notes = "编辑消防排班计划")
    public R editFireFightShiftPlan(@Validated(GroupAction.UpdateAction.class) @RequestBody FireFightShiftPlanSubmitReqDTO reqDTO) {
        return R.status(fightShiftPlanService.editFireFightShiftPlan(reqDTO));
    }

    /**
     * 删除消防排班计划
     */
    @PostMapping("/deleteFireFightShiftPlan/{shiftPlanId}")
    @ApiOperation(value = "删除消防排班计划", notes = "删除消防排班计划")
    public R deleteFireFightShiftPlan(@PathVariable Long shiftPlanId) {
        return R.status(fightShiftPlanService.deleteFireFightShiftPlan(shiftPlanId));
    }

    /**
     * 获取当前值班信息(前端需要做下定时刷新，班次可能会变)
     */
    @PostMapping("/getFireFightShiftDutyInfo")
    @ApiOperation(value = "获取当前值班信息", notes = "获取当前值班信息")
    public R<List<FireFightShiftDutyInfoVO>> getFireFightShiftDutyInfo(@RequestBody FireFightShiftPlanReqDTO reqDTO) {
        return R.data(fightShiftPlanService.getFireFightShiftDutyInfo(reqDTO));
    }

    /**
     * 获取值班记录分页列表
     */
    @PostMapping("/findFireFightDutyRecordsPage")
    @ApiOperation(value = "获取值班记录分页列表", notes = "获取值班记录分页列表")
    public R<NestPage<FireFightDutyRecordsVO>> findFireFightDutyRecordsPage(@RequestBody FireFightDutyRecordsReqDTO reqDTO) {
        return R.data(fireFightDutyRecordsService.findFireFightDutyRecordsPage(reqDTO));
    }


}
