package jnpf.personnels.controller.web.formtype;

import com.github.pagehelper.PageInfo;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.personnels.dto.staff.field.FtbPersonnelsRegistrationFormTypeDto;
import jnpf.model.personnels.req.field.QueryRegistrationFormTypeListReq;
import jnpf.model.personnels.req.field.SaveRegistrationFormTypeReq;
import jnpf.personnels.service.FtbPersonnelsRegistrationFormTypeService;
import jnpf.util.FtbUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * web登记表类型 表模块
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/web/personnels-registration-form-type")
public class FtbPersonnelsRegistrationFormTypeController {


    @Autowired
    private FtbPersonnelsRegistrationFormTypeService registrationFormTypeService;

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

    /**
     * 查询所有登记表类别
     *
     * @return {@link ActionResult}<{@link FtbPersonnelsRegistrationFormTypeDto}>
     */
    @GetMapping("/query-list-all")
    public ActionResult<List<FtbPersonnelsRegistrationFormTypeDto>> listAll() {
        List<FtbPersonnelsRegistrationFormTypeDto> list = registrationFormTypeService.listAll(null);
        return ActionResult.success(list);
    }

    /**
     * 查询所有已经启用的登记表类别(用户添加自定义字段)
     *
     * @return {@link ActionResult}<{@link FtbPersonnelsRegistrationFormTypeDto}>
     */
    @GetMapping("/query-list-enable-all")
    public ActionResult<List<FtbPersonnelsRegistrationFormTypeDto>> listEnableAll() {
        List<FtbPersonnelsRegistrationFormTypeDto> list = registrationFormTypeService.listAll(0);
        return ActionResult.success(list);
    }

    /**
     * 切换启用/禁用
     *
     * @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) {
        registrationFormTypeService.switchStatus(id, status);
        return ActionResult.success();
    }

    /**
     * 添加登记表类型，返回主键id
     *
     * @param req 参数
     * @return {@link ActionResult}<{@link String}>
     */
    @PostMapping("/add")
    public ActionResult<String> add(@Validated @RequestBody SaveRegistrationFormTypeReq req) {
        String id = registrationFormTypeService.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 SaveRegistrationFormTypeReq req) {
        req.setId(id);
        registrationFormTypeService.updateData(req);
        return ActionResult.success();
    }


    /**
     * 修改排序
     *
     * @param id    主键ID
     * @param sorts 序号
     * @return {@link ActionResult}
     */
    @PutMapping("/update-sorts/{id}/{sorts}")
    public ActionResult updateSorts(@PathVariable("id") String id, @PathVariable("sorts") Long sorts) {
        registrationFormTypeService.updateSorts(id, sorts);
        return ActionResult.success();
    }


    /**
     * 删除登记表类别
     *
     * @param id 主键id，必传
     * @return {@link ActionResult}
     */
    @DeleteMapping("/delete/{id}")
    public ActionResult delete(@PathVariable("id") String id) {
        registrationFormTypeService.deleteData(id);
        return ActionResult.success();
    }
}
