package jnpf.personnels.controller.web.resignation;

import cn.hutool.core.collection.CollUtil;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.personnels.dto.resignation.FtbResignationConfigurationDTO;
import jnpf.model.personnels.vo.resignation.FtbResignationConfigurationVO;
import jnpf.personnels.service.FtbPersonnelsResignationConfigurationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * web离职原因配置
 *
 * @author wangchunxiang
 * @date 2024/06/28
 */
@RestController
@RequestMapping("/web/resignation-configuration")
public class FtbResignationConfigurationController {

    @Resource
    private FtbPersonnelsResignationConfigurationService ftbPersonnelsResignationConfigurationService;


    /**
     * 离职原因配置列表
     *
     * @param resignationTypeId 离职原因类型id
     * @param keyWords 离职原因
     * @return {@link ActionResult }<{@link List }<{@link FtbResignationConfigurationVO }>>
     */
    @GetMapping("/list")
    public ActionResult<PageListVO<FtbResignationConfigurationVO>> getList(String keyWords, String resignationTypeId, CultivatePage page) {
        PageListVO<FtbResignationConfigurationVO> result = ftbPersonnelsResignationConfigurationService.getList(keyWords, resignationTypeId, page);
        return ActionResult.success(result);
    }

    /**
     * 离职原因配置保存
     *
     * @return {@link ActionResult }
     */
    @PostMapping("/configuration-save")
    public ActionResult<Void> saveOrUpdate(@RequestBody List<FtbResignationConfigurationDTO> resignationConfigurationDTO) {
        ftbPersonnelsResignationConfigurationService.configurationSave(resignationConfigurationDTO);
        return ActionResult.success();
    }
    /**
     * 离职原因配置删除
     */
    @DeleteMapping("/delete/{id}")
    public ActionResult<Void> delete(@PathVariable("id") String id) {
        ftbPersonnelsResignationConfigurationService.removeById(id);
        return ActionResult.success();
    }

    /**
     * 离职原因下拉列表(办理离职时)
     *
     * @return {@link ActionResult }<{@link List }<{@link FtbResignationConfigurationVO }>>
     */
    @GetMapping("/reason-for-resignation-drop-down")
    public ActionResult<List<FtbResignationConfigurationVO>> reasonForResignationDropDown(Integer individualApplication) {
        List<FtbResignationConfigurationVO> result = ftbPersonnelsResignationConfigurationService.reasonForResignationDropDown(individualApplication);
        if (CollUtil.isEmpty(result)) {
            return ActionResult.fail("暂无原因可选，请联系管理员!");
        }
        return ActionResult.success(result);
    }


}
