package com.caliverse.admin.history.domain;

import com.caliverse.admin.domain.adminlog.FieldChange;
import com.caliverse.admin.domain.entity.HISTORYTYPE;
import com.caliverse.admin.global.common.utils.DateUtils;
import com.caliverse.admin.history.entity.DBType;
import com.caliverse.admin.history.entity.EDBOperationType;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.Getter;
import lombok.Setter;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;

@Getter
@Setter
@Document(collection = "historyLog")
public class MysqlHistoryLogInfo extends HistoryLogInfoBase {

    private Object data;

    public MysqlHistoryLogInfo(EDBOperationType operationType, HISTORYTYPE historytype, String tableName, String message, String tranId, List<FieldChange> changed, String userId, String userIP, Object data) {
        super(DBType.MYSQL, DateUtils.nowDateTime(), operationType, historytype, tableName, message, tranId, changed, userId, userIP);

        this.data = data;
//        this.data = deepCopy(data);
    }

//    private Object deepCopy(Object source) {
//        try {
//            if (source == null) return null;
//
//            ObjectMapper mapper = new ObjectMapper()
//                    .setSerializationInclusion(JsonInclude.Include.NON_NULL)
//                    .registerModule(new JavaTimeModule());
//
//            String json = mapper.writeValueAsString(source);
//            return mapper.readValue(json, Object.class);
//        } catch (Exception e) {
//            return source;
//        }
//    }
}
