package com.jeeplus.human.enrollment.enrollmentRegistration.controller;

import com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentCertificateInfo;
import com.jeeplus.human.enrollment.enrollmentRegistration.service.EnrollmentCertificateInfoService;
import com.jeeplus.logging.annotation.ApiLog;
import com.jeeplus.logging.constant.enums.LogTypeEnum;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author 王强
 * @version 1.0
 */
@Slf4j
@RestController
@Api("资质证书")
@RequestMapping(value = "/certificateInfo")
public class EnrollmentCertificateInfoController {

    @Resource
    private EnrollmentCertificateInfoService service;


    /**
     * 保存资质证书
     * @return
     */
    @ApiLog(value = "保存资质证书", type = LogTypeEnum.SAVE)
    @PostMapping("save")
    public ResponseEntity save(@Valid @RequestBody EnrollmentCertificateInfo info) throws Exception {
        service.saveOrUpdateInfo(info);
        return ResponseEntity.ok ("操作成功");
    }

    /**
     * 删除资质证书
     * @return
     */
    @ApiLog(value = "删除资质证书", type = LogTypeEnum.SAVE)
    @PostMapping("delete")
    public ResponseEntity<String> delete(@Valid @RequestBody EnrollmentCertificateInfo info) throws Exception {
        service.removeById(info.getId());
        return ResponseEntity.ok ("操作成功");
    }

    /**
     * 资质证书
     * @return
     */
    @ApiLog(value = "资质证书", type = LogTypeEnum.SAVE)
    @GetMapping("list")
    public ResponseEntity<List<EnrollmentCertificateInfo>> findList(EnrollmentCertificateInfo info) throws Exception {
        List<EnrollmentCertificateInfo> list = service.findByUserId(info.getUserId(),"5");
        return ResponseEntity.ok (list);
    }

    /**
     * 根据id查询资质证书
     * @return
     */
    @ApiLog(value = "根据id查询资质证书信息", type = LogTypeEnum.SAVE)
    @GetMapping("findById")
    public ResponseEntity<EnrollmentCertificateInfo> findById(EnrollmentCertificateInfo info) throws Exception {
        EnrollmentCertificateInfo res = service.findById(info.getId());
        return ResponseEntity.ok (res);
    }

    /**
     * 资质证书用户端列表
     * @return
     */
    @ApiLog(value = "资质证书用户端列表", type = LogTypeEnum.SAVE)
    @GetMapping("findAuditList")
    public ResponseEntity<List<EnrollmentCertificateInfo>> findAuditList(EnrollmentCertificateInfo info) throws Exception {
        List<EnrollmentCertificateInfo> list = service.findByUserId(info.getUserId(),"1");
        return ResponseEntity.ok (list);
    }
}
