syntax = "proto3";
package eventpb;
option go_package = "github.com/pingcap/ticdc/eventpb";

import "heartbeatpb/heartbeat.proto";

message EventFilterRule {
    repeated string matcher = 1;
    repeated string ignore_event = 2;
    repeated string ignore_sql = 3;
    string ignore_insert_value_expr = 4;
    string ignore_update_new_value_expr = 5;
    string ignore_update_old_value_expr = 6;
    string ignore_delete_value_expr = 7;
}

message InnerFilterConfig {
    repeated string rules = 1;
    repeated uint64 ignore_txn_start_ts = 2;
    repeated EventFilterRule EventFilters = 3;
}

message FilterConfig {
    bool caseSensitive = 1;
	bool forceReplicate = 2;
    InnerFilterConfig filterConfig = 3;
}


message ResolvedTs {

}

enum OpType {
	OpTypePut = 0;
	OpTypeDelete = 1;
}

message Event {
    bytes key = 1;
	// nil for delete type
	bytes value = 2;
	// nil for insert type
	bytes OldValue = 3;
    OpType op_type = 4;

}

message TxnEvent {
    repeated Event events = 1;
    uint64 commit_ts = 2;
    uint64 start_ts = 3;
}

message TableInfo {

}

message EventFeed {
    repeated TxnEvent txn_events = 1; 
    uint64 resolved_ts = 2; 
    heartbeatpb.DispatcherID dispatcher_id = 3; 
    float ratio = 4; 
    TableInfo table_info = 5; 
}

enum ActionType {
    ACTION_TYPE_UNSPECIFIED = 0;
    ACTION_TYPE_REGISTER = 1;
    ACTION_TYPE_REMOVE = 2;
    // 3 and 4 are deprecated.
    ACTION_TYPE_RESET = 5;
}

message IntegrityConfig {
	string IntegrityCheckLevel  = 1;
	string CorruptionHandleLevel  = 2;
}

// DispatcherRequest is used to send a dispatcher request to the event service.
// A request can be a register, remove, reset dispatcher request.
message DispatcherRequest {
    // cluster_id is the id of the TiDB cluster that the dispatcher belongs to.
    uint64 cluster_id = 1;
    heartbeatpb.ChangefeedID changefeed_id = 2;
    heartbeatpb.DispatcherID dispatcher_id = 3;
    heartbeatpb.TableSpan table_span = 4;
    uint64 start_ts = 5;
    string server_id = 6;
    ActionType action_type = 7;
    FilterConfig filter_config = 8;
    bool enable_sync_point = 9;
    uint64 sync_point_ts = 10;
    uint64 sync_point_interval = 11;
    bool only_reuse = 12;
    bool bdr_mode = 13;
    IntegrityConfig integrity = 14;
	string timezone = 15;
    uint64 epoch = 16;
    bool output_raw_change_event = 17;
    int64 mode = 18;
    string txn_atomicity = 19;
}
