package cc.smtweb.framework.core.common;

import java.util.Map;

/**
 * @Author yaoq
 * @Date 2022年09月13日 18:20
 * @Description
 */
public class CanalVO {
    private String tableName; // 表名
    private String schemaName; // 库名
    private String type; // 类型（更新、删除、插入）
    private Map<String, String> data; // 数据JSON  自己转对应表格实体类
    private String idField;  // 更新或删除都是根据ID来
    private String id;  // 更新或删除都是根据ID来
    private String sql; // 执行的sql

    public static CanalVO ok(String schemaName, String tableName, String type, Map<String, String> data, String sql, String idField, String id) {
        CanalVO canalVO = new CanalVO();
        canalVO.setId(id);
        canalVO.setSchemaName(schemaName);
        canalVO.setTableName(tableName);
        canalVO.setType(type);
        canalVO.setIdField(idField);
        canalVO.setData(data);
        canalVO.setSql(sql);
        return canalVO;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getSchemaName() {
        return schemaName;
    }

    public void setSchemaName(String schemaName) {
        this.schemaName = schemaName;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Map<String, String> getData() {
        return data;
    }

    public void setData(Map<String, String> data) {
        this.data = data;
    }

    public String getIdField() {
        return idField;
    }

    public void setIdField(String idField) {
        this.idField = idField;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getSql() {
        return sql;
    }

    public void setSql(String sql) {
        this.sql = sql;
    }

    public boolean createIs() {
        return SwEnum.DbEventType.CREATE.value.equals(type);
    }

    public boolean alterIs() {
        return SwEnum.DbEventType.ALTER.value.equals(type);
    }

    public boolean insertIs() {
        return SwEnum.DbEventType.INSERT.value.equals(type);
    }

    public boolean updateIs() {
        return SwEnum.DbEventType.UPDATE.value.equals(type);
    }

    public boolean deleteIs() {
        return SwEnum.DbEventType.DELETE.value.equals(type);
    }
}
