package com.caliverse.admin.mongodb.domain;

import com.caliverse.admin.domain.entity.FieldChange;
import com.caliverse.admin.domain.entity.HISTORYTYPEDETAIL;
import com.caliverse.admin.global.common.utils.DateUtils;
import com.caliverse.admin.mongodb.entity.DBType;
import com.caliverse.admin.mongodb.entity.EDBOperationType;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;
import java.util.List;

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

    private Object data;

    public MysqlHistoryLogInfo(EDBOperationType operationType, HISTORYTYPEDETAIL historyType, String tableName, String message, String tranId, List<FieldChange> changed, String userId, String userIP, Object data) {
        super(DBType.MYSQL, LocalDateTime.now(), 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;
//        }
//    }
}
