package com.citygis.web.dataEncrypt.controller;

import com.citygis.common.annotation.Log;
import com.citygis.common.core.domain.AjaxResult;
import com.citygis.common.enums.BusinessType;
import com.citygis.web.dataEncrypt.service.DataEncryptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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;

/**
 * @Author: zyl
 * @CreateTime: 2025-02-19
 * @Description: 加密机数据加密
 * @Version: 1.0
 */
@Api(tags = "隐私数据加密")
@RestController
@RequestMapping("/web/dataEncrypt")
public class DataEncryptController {

    @Resource
    DataEncryptService dataEncryptService;

    @ApiOperation("数据加密")
    @Log(title = "隐私数据加密", businessType = BusinessType.OTHER)
    @PostMapping("/dataEncrypt")
    public AjaxResult dataEncrypt(@RequestBody String plainText) throws Exception {
        return AjaxResult.success(dataEncryptService.dataEncrypt(plainText));
    }

    @ApiOperation("数据解密")
    @Log(title = "隐私数据加密", businessType = BusinessType.OTHER)
    @PostMapping("/dataDecrypt")
    public AjaxResult dataDecrypt(@RequestBody String encryptedBase64) throws Exception {
        return AjaxResult.success(dataEncryptService.dataDecrypt(encryptedBase64));
    }

    @ApiOperation("hmac运算")
    @Log(title = "隐私数据加密", businessType = BusinessType.OTHER)
    @PostMapping("/generateHmac")
    public AjaxResult generateHmac(@RequestBody String encryptedBase64) throws Exception {
        return AjaxResult.success(dataEncryptService.generateHmac(encryptedBase64));
    }

}
