package jnpf.cultivate.v2.controller.app.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.enums.cultivate.ApplySourceEnum;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.cultivate.v2.apply.req.V2IdentifyApplyListAppReq;
import jnpf.model.cultivate.v2.apply.req.V2IdentifyApplySaveReq;
import jnpf.model.cultivate.v2.apply.req.V2IdentifyApplySubmitReq;
import jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyAppBasicInfoVo;
import jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyItemVo;
import jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyListAppVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * app鉴定管理模块
 */
@Slf4j
@RestController
@RequestMapping(value = "/v2/app/apply/manager")
public class V2CultivateIdentifyManagerAppController {
    @Autowired
    private V2CultivateIdentifyApplyService applyService;


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


    /**
     * 实操鉴定列表
     *
     * @param req 帅选条件
     * @return 列表
     * @
     */
    @Operation(summary = "列表")
    @PostMapping(value = "/list")
    public ActionResult<PageListVO<V2IdentifyApplyListAppVo>> queryAppIdentifyApplyList(@Valid @RequestBody V2IdentifyApplyListAppReq req) {
        return ActionResult.success(CultivatePage.coverPageList(applyService.queryAppIdentifyApplyList(req)));
    }


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

    /**
     * 获取鉴定项列表
     *
     * @param id 鉴定申请ID
     */
    @Operation(summary = "详情(鉴定详情)")
    @GetMapping(value = "/item-list/{id}")
    public ActionResult<V2IdentifyApplyItemVo> itemList(@PathVariable("id") String id) {
        return ActionResult.success(applyService.itemList(id));
    }


    /**
     * 提交鉴定
     *
     * @param req
     */
    @Operation(summary = "提交鉴定")
    @PostMapping(value = "/submit")
    public ActionResult<Void> submit(@Valid @RequestBody V2IdentifyApplySubmitReq req) {
        applyService.applyDataSubmit(req);
        return ActionResult.success(MsgCode.SU005.get());
    }

}
