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

import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.msg.center.domain.persistence.BaseEntityExt;
import cn.axzo.msg.center.domain.utils.IgnorePropsJsonTypeHandler;
import cn.axzo.msg.center.service.enums.CardBizState;
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;

    /**
     * 发起者的自然人ID
     */
    private Long senderPersonId;

    /**
     * 发起人的单位id
     */
    private Long senderOuId;

    /**
     * 发起者项目id
     */
    private Long senderWorkspaceId;

    /**
     * 接收人自然人id
     */
    private Long receiverPersonId;

    /**
     * 接收人单位id
     */
    private Long receiverOuId;

    /**
     * 接收人项目id
     */
    private Long receiverWorkspaceId;

    /**
     * 端类型
     */
    private AppTypeEnum receiverAppType;

    /**
     * 接收账号
     */
    private String imReceiveAccount;

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

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

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

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

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

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

    /**
     * 业务状态
     */
    private CardBizState 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 key, Object value) {
        if (logContent == null)
            logContent = new JSONObject();
        logContent.put(key, value);
    }

    @Setter
    @Getter
    public static class RecordExt {
    }

}