package com.sunyard.chsm.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sunyard.chsm.constant.AuditLogConst;
import com.sunyard.chsm.model.R;
import com.sunyard.chsm.model.dto.CertDTO;
import com.sunyard.chsm.service.AppCertService;
import com.sunyard.ssp.common.annotation.AuditControllerLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
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 javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 应用证书管理接口
 *
 * @author liulu
 * @since 2024/11/6
 */
@Slf4j
@RestController
@RequestMapping("/app/cert")
public class AppCertController {

    @Resource
    private AppCertService appCertService;

    /**
     * 分页查询应用证书列表
     *
     * @param query 查询条件
     * @return 应用列表
     */
    @GetMapping("/pageList")
    public R<Page<CertDTO.ACView>> queryPageList(CertDTO.Query query) {

        Page<CertDTO.ACView> page = appCertService.selectPageList(query);

        return R.data(page);
    }


    /**
     * 导入证书
     *
     * @param importCert 证书
     */
    @PostMapping("/import")
    public R<Void> importCert(@Valid @RequestBody CertDTO.ImportCert importCert) {
        appCertService.importCert(importCert);
        return R.ok();
    }

    /**
     * 删除证书
     *
     * @param id id
     * @return void
     */
    @DeleteMapping
    @AuditControllerLog(description = "删除证书", operateType = AuditLogConst.DELETE)
    public R<Void> delete(Long id) {
        appCertService.delete(id);
        return R.ok();
    }

}
