package com.njcn.gather.icd.mapping.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.LogUtil;
import com.njcn.gather.icd.mapping.pojo.param.IcdCheckResultSaveParam;
import com.njcn.gather.icd.mapping.pojo.vo.MmsDeviceTypeVO;
import com.njcn.gather.icd.mapping.pojo.vo.PqdifCheckPlaceholderVO;
import com.njcn.gather.icd.mapping.service.MmsDeviceTypeService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 设备类型校验入口。
 */
@Slf4j
@Api(tags = "设备类型ICD校验")
@RestController
@RequestMapping("/api/mms-mapping/dev-types")
@RequiredArgsConstructor
public class MmsDeviceTypeController extends BaseController {

    private final MmsDeviceTypeService mmsDeviceTypeService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查询设备类型校验列表")
    @GetMapping
    public HttpResult<List<MmsDeviceTypeVO>> listDeviceTypes() {
        String methodDescribe = getMethodDescribe("listDeviceTypes");
        LogUtil.njcnDebug(log, "{}，开始查询设备类型校验列表", methodDescribe);
        List<MmsDeviceTypeVO> result = mmsDeviceTypeService.listDeviceTypes();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("保存设备类型ICD唯一性校验结果")
    @ApiImplicitParam(name = "id", value = "设备类型ID", required = true)
    @PostMapping("/{id}/icd-check-result")
    public HttpResult<Boolean> saveIcdCheckResult(@PathVariable("id") String id,
                                                  @RequestBody IcdCheckResultSaveParam param) {
        String methodDescribe = getMethodDescribe("saveIcdCheckResult");
        LogUtil.njcnDebug(log, "{}，开始保存设备类型ICD校验结果，devTypeId={}", methodDescribe, id);
        boolean result = mmsDeviceTypeService.saveIcdCheckResult(id, param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("设备类型PQDIF校验")
    @ApiImplicitParam(name = "id", value = "设备类型ID", required = true)
    @PostMapping("/{id}/pqdif-check")
    public HttpResult<PqdifCheckPlaceholderVO> pqdifCheck(@PathVariable("id") String id) {
        String methodDescribe = getMethodDescribe("pqdifCheck");
        LogUtil.njcnDebug(log, "{}，设备类型PQDIF校验预留入口，devTypeId={}", methodDescribe, id);
        PqdifCheckPlaceholderVO result = mmsDeviceTypeService.pqdifCheck(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
}
