package cn.axzo.msg.center.domain.entity;

import cn.axzo.msg.center.domain.persistence.BaseEntityExt;
import cn.axzo.msg.center.domain.utils.IgnorePropsJsonTypeHandler;
import cn.axzo.msg.center.service.enums.CardState;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * @author yanglin
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName(value = "card_log", autoResultMap = true)
public class CardLog extends BaseEntityExt<CardLog> {
    /**
     * 卡片唯一标识码
     */
    private String identityCode;

    /**
     * 异常
     */
    private String error;

    /**
     * 业务消息ID
     */
    private String bizMessageId;

    /**
     * 模版编码
     */
    private String templateCode;

    /**
     * 业务编码
     */
    private String bizCode;

    /**
     * 流程类代办的流程结点编码
     */
    private String subBizCode;

    /**
     * 卡片状态
     */
    private CardState cardState;

    /**
     * 业务状态
     */
    private String bizState;

    /**
     * 上下文
     */
    private String context;

    /**
     * 批次号
     */
    private String batchNo;

    /**
     * 卡片内容
     */
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private Object cardContent;

    /**
     * 日志内容
     */
    @TableField(typeHandler = IgnorePropsJsonTypeHandler.class)
    private JSONObject logContent;

    /**
     * 扩展字段
     */
    @TableField(typeHandler = IgnorePropsJsonTypeHandler.class)
    private Card.RecordExt recordExt;

    public void addLogContent(String name, Object value) {
        if (logContent == null)
            logContent = new JSONObject();
        logContent.put(name, value);
    }

    @Setter
    @Getter
    public static class RecordExt {
    }

}