package com.lanyuanxiaoyao.service.executor.task.entity;

import cn.hutool.core.util.StrUtil;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 记录
 *
 * @author lanyuanxiaoyao
 * @date 2024-01-09
 */
public class RecordView implements Serializable, Comparable<RecordView> {
    private Operation operation;
    private String data;
    private String timestamp;
    private String file;
    private Map<String, Object> attributes;

    public RecordView() {}

    public RecordView(Operation operation, String data, String timestamp, String file) {
        this.operation = operation;
        this.data = data;
        this.timestamp = timestamp;
        this.file = file;
        this.attributes = new HashMap<>();
    }

    public Operation getOperation() {
        return operation;
    }

    public void setOperation(Operation operation) {
        this.operation = operation;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    public Map<String, Object> getAttributes() {
        return attributes;
    }

    public void setAttributes(Map<String, Object> attributes) {
        this.attributes = attributes;
    }

    @Override
    public String toString() {
        return StrUtil.format("{} {} {} {}", operation, timestamp, file, data);
    }

    @Override
    public int compareTo(RecordView o) {
        if (o != null) {
            return this.timestamp.compareTo(o.timestamp);
        }
        return 0;
    }

    public enum Operation {
        DELETE, UPSERT, ROLLBACK, RESULT, SOURCE, QUEUE, TARGET
    }
}
