package jnpf.personnels.controller.web.formfield;

import com.github.pagehelper.PageInfo;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.personnels.dto.staff.field.FtbPersonnelsRegistrationFormFieldDto;
import jnpf.model.personnels.dto.staff.field.FtbPersonnelsRegistrationFormTypeDto;
import jnpf.model.personnels.req.field.QueryRegistrationFormFieldListReq;
import jnpf.model.personnels.req.field.SaveRegistrationFormFieldReq;
import jnpf.personnels.service.FtbPersonnelsRegistrationFormFieldService;
import jnpf.util.FtbUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * web登记表字段模块
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/web/personnels-registration-form-field")
public class FtbPersonnelsRegistrationFormFieldController {

    @Autowired
    private FtbPersonnelsRegistrationFormFieldService registrationFormFieldService;

    /**
     * 登记表类别列表
     *
     * @param req
     * @return {@link ActionResult}<{@link FtbPersonnelsRegistrationFormTypeDto}>
     */
    @GetMapping("/query-list")
    public ActionResult<PageListVO<FtbPersonnelsRegistrationFormFieldDto>> pageLists(QueryRegistrationFormFieldListReq req) {
        PageInfo<FtbPersonnelsRegistrationFormFieldDto> pageVo = registrationFormFieldService.getPageList(req);
        return ActionResult.page(pageVo.getList(), FtbUtil.getPagination(pageVo));
    }

    /**
     * 切换启用/禁用
     *
     * @param id     主键ID
     * @param status 0、启用  1、禁用
     * @return {@link ActionResult}
     */
    @PutMapping("/switch-status/{id}/{status}")
    public ActionResult switchStatus(@PathVariable("id") String id, @PathVariable("status") Integer status) {
        registrationFormFieldService.switchStatus(id, status);
        return ActionResult.success();
    }

    /**
     * 查询详情
     *
     * @param id 主键ID
     * @return {@link ActionResult}
     */
    @GetMapping("/get/{id}")
    public ActionResult<FtbPersonnelsRegistrationFormFieldDto> get(@PathVariable("id") String id) {
        FtbPersonnelsRegistrationFormFieldDto info = registrationFormFieldService.getInfo(id);
        return ActionResult.success("成功", info);
    }


    /**
     * 切换 必填/选填
     *
     * @param id     主键ID
     * @param status 是否必填，0、选填 1、必填
     * @return {@link ActionResult}
     */
    @PutMapping("/switch-fill/{id}/{status}")
    public ActionResult switchNeedFill(@PathVariable("id") String id, @PathVariable("status") Integer status) {
        registrationFormFieldService.switchNeedFill(id, status);
        return ActionResult.success();
    }

    /**
     * 添加登记表字段，返回主键id
     *
     * @param req 参数
     * @return {@link ActionResult}<{@link String}>
     */
    @PostMapping("/add")
    public ActionResult<String> add(@Validated @RequestBody SaveRegistrationFormFieldReq req) {
        String id = registrationFormFieldService.insertData(req);
        return ActionResult.success("成功", id);
    }


    /**
     * 修改字段信息
     *
     * @param id  主键ID
     * @param req
     * @return {@link ActionResult}
     */
    @PutMapping("/update/{id}")
    public ActionResult update(@PathVariable("id") String id, @Validated @RequestBody SaveRegistrationFormFieldReq req) {
        req.setId(id);
        registrationFormFieldService.updateData(req);
        return ActionResult.success();
    }


    /**
     * 删除 字段
     *
     * @param id 主键id，必传
     * @return {@link ActionResult}
     */
    @DeleteMapping("/delete/{id}")
    public ActionResult delete(@PathVariable("id") String id) {
        registrationFormFieldService.deleteData(id);
        return ActionResult.success();
    }

    /**
     * 切换员工是否可见
     *
     * @param id     主键ID
     * @param status 0、可见 1、不可见
     * @return {@link ActionResult}
     */
    @PutMapping("/switch-visible/{id}/{status}")
    public ActionResult switchVisible(@PathVariable("id") String id, @PathVariable("status") Integer status) {
        registrationFormFieldService.switchVisible(id, status);
        return ActionResult.success();
    }

    /**
     * 切换员工是否可修改本人档案
     *
     * @param id     主键ID
     * @param status 0、可以修改 1、不能修改
     * @return {@link ActionResult}
     */
    @PutMapping("/toggle-modify-your-profile/{id}/{status}")
    public ActionResult toggleWhetherYouCanModifyYourProfile(@PathVariable("id") String id, @PathVariable("status") Integer status) {
        registrationFormFieldService.toggleWhetherYouCanModifyYourProfile(id, status);
        return ActionResult.success();
    }

    /**
     * 动态查询登记字段值
     * @param field 字段名称
     * @param workType 工作状态
     */
    @GetMapping("/query-field-value")
    public ActionResult<List<Map<String,String>>> queryFieldValue(String field, String workType) {
        List<Map<String,String>> value = registrationFormFieldService.queryFieldValue(field,workType);
        return ActionResult.success("成功", value);
    }

    /**
     * 试用期登记字段值-forOA
     * @param workType 工作状态
     */
    @GetMapping("/query-field-value-probationPeriod-oa")
    public ActionResult<List<Map<String,String>>> probationPeriod(String workType) {
        List<Map<String,String>> value = registrationFormFieldService.queryFieldValue("试用期",workType);
        return ActionResult.success("成功", value);
    }

    /**
     * 员工状态登记字段值-forOA
     */
    @GetMapping("/query-field-value-employeeStatus-oa")
    public ActionResult<List<Map<String,String>>> employeeStatus() {
        List<Map<String,String>> value = registrationFormFieldService.queryFieldValue("员工状态",null);
        return ActionResult.success("成功", value);
    }

}
