package jnpf.cultivate.v2.controller.web.identify;

import io.swagger.v3.oas.annotations.Operation;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.constant.MsgCode;
import jnpf.cultivate.v2.service.V2CultivateIdentifyApplyService;
import jnpf.entity.cultivate.CultivateIdentifyItems;
import jnpf.enums.cultivate.ApplySourceEnum;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.cultivate.v2.apply.req.V2IdentifyApplyListReq;
import jnpf.model.cultivate.v2.apply.req.V2IdentifyApplySaveReq;
import jnpf.model.cultivate.v2.apply.req.V2IdentifyApplySubmitReq;
import jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyBasicInfoVo;
import jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyInfoVo;
import jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyListVo;
import jnpf.model.cultivate.vo.identify.IdentifyApplyDetailsInfoVo;
import jnpf.util.ConstantUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * web实操鉴定用户申请模块
 *
 * @author mouzeping
 */
@Slf4j
@RestController
@RequestMapping(value = "/v2/web/identify/apply")
public class V2CultivateIdentifyApplyController {

    @Autowired
    private V2CultivateIdentifyApplyService applyService;

    /**
     * 获取实操鉴定申请列表
     *
     * @param req 查询条件对象，包含分页和筛选参数
     * @return 包含分页结果的ActionResult对象，数据为PageListVO<V2IdentifyApplyListVo>类型
     */
    @Operation(summary = "列表")
    @GetMapping(value = "/list")
    public ActionResult<PageListVO<V2IdentifyApplyListVo>> getWebPageApplyList(@Valid V2IdentifyApplyListReq req) {
        return ActionResult.success(CultivatePage.coverPageList(applyService.getWebPageApplyList(req)));
    }


    /**
     * 发起实操鉴定申请
     *
     * @param req 实操鉴定申请保存请求对象，包含申请相关信息
     * @return 操作结果的ActionResult对象
     */
    @PostMapping(value = "/save")
    public ActionResult<Void> applyDataSave(@Valid @RequestBody V2IdentifyApplySaveReq req) {
        req.setSource(ApplySourceEnum.SDFQ.getCode());
        applyService.applyDataSaveBatch(req);
        return ActionResult.success(MsgCode.SU018.get());
    }


    /**
     * 重新发起鉴定申请
     *
     * @param id 需要重新鉴定的申请ID
     * @return 操作结果的ActionResult对象
     */
    @Operation(summary = "重新鉴定")
    @PutMapping(value = "/reIdentify/{id}")
    public ActionResult<Void> applyDataReIdentify(@PathVariable("id") String id) {
        applyService.applyDataReIdentify(id);
        return ActionResult.success(MsgCode.SU005.get());
    }


    /**
     * 删除实操鉴定申请
     *
     * @param id 需要删除的鉴定申请ID
     * @return 操作结果的ActionResult对象
     */
    @Operation(summary = "删除")
    @DeleteMapping(value = "/delete/{id}")
    public ActionResult<Void> applyDataDelete(@PathVariable("id") String id) {
        applyService.applyDataDelete(id, ConstantUtil.NUM_TRUE);
        return ActionResult.success(MsgCode.SU003.get());
    }


    /**
     * 获取实操鉴定申请的基本信息详情
     *
     * @param id 鉴定申请ID
     * @return 包含基本信息的ActionResult对象，数据为V2IdentifyApplyBasicInfoVo类型
     */
    @Operation(summary = "详情(基本信息)")
    @GetMapping(value = "/basicInfo/{id}")
    public ActionResult<V2IdentifyApplyBasicInfoVo> getApplyBasicInfo(@PathVariable("id") String id) {
        return ActionResult.success(applyService.getWebApplyBasicInfo(id));
    }

    /**
     * 获取实操鉴定申请的详细信息
     *
     * @param id 鉴定申请ID
     * @return 包含详细信息的ActionResult对象，数据为V2IdentifyApplyInfoVo类型
     */
    @Operation(summary = "详情(鉴定详情)")
    @GetMapping(value = "/info/{id}")
    public ActionResult<V2IdentifyApplyInfoVo> getApplyInfo(@PathVariable("id") String id) {
        return ActionResult.success(applyService.getWebApplyInfo(id));
    }

    /**
     * 重新提交鉴定记录 - 查询新鉴定项
     *
     * @param id 鉴定申请ID
     * @return 操作结果的ActionResult对象
     */
    @Operation(summary = "重新提交鉴定记录 - 查询新鉴定项")
    @GetMapping(value = "/regenerate/{id}")
    public ActionResult<List<IdentifyApplyDetailsInfoVo>> regenerateIdentifyApply(@PathVariable("id") String id) {
        List<IdentifyApplyDetailsInfoVo> items = applyService.regenerateIdentifyApply(id);
        return ActionResult.success(items);
    }

    /**
     * 重新提交鉴定记录
     *
     * @param req 参数
     */
    @Operation(summary = "重新提交鉴定记录")
    @PostMapping(value = "/re-submit")
    public ActionResult<Void> reSubmit(@Valid @RequestBody V2IdentifyApplySubmitReq req) {

        applyService.reSubmit(req);
        return ActionResult.success();
    }
}


