package com.zsElectric.boot.thirdParty.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

/**
 * 第三方接入通用响应实体
 *
 * @author wzq
 */
@Data
public class ThirdPartyResponse implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 响应状态码
     * 0000: 请求成功
     * 500: 系统错误
     * 4001: 签名错误
     * 4002: token错误
     * 4003: 参数不合法,缺少必需的参数: operatorId、sig、timeStamp、data、seq
     * 4004: 请求的业务参数不合法
     */
    @JsonProperty("ret")
    private Integer ret;

    /**
     * 响应消息
     */
    @JsonProperty("msg")
    private String msg;

    /**
     * 响应加密数据 - AES 128位加密(CBC模式, PKCS5Padding)
     */
    @JsonProperty("data")
    private String data;

    /**
     * 响应签名 - HMAC-MD5签名(大写)
     * 出参拼接顺序: ret + msg + data
     */
    @JsonProperty("sig")
    private String sig;

    /**
     * 创建成功响应
     */
    public static ThirdPartyResponse success(String encryptedData, String sig) {
        ThirdPartyResponse response = new ThirdPartyResponse();
        response.setRet(0);
        response.setMsg("");
        response.setData(encryptedData);
        response.setSig(sig);
        return response;
    }

    /**
     * 创建错误响应
     */
    public static ThirdPartyResponse error(Integer ret, String msg, String sig) {
        ThirdPartyResponse response = new ThirdPartyResponse();
        response.setRet(ret);
        response.setMsg(msg);
        response.setData("");
        response.setSig(sig);
        return response;
    }
}
