// Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto2";

package dtpb;

import "index_file_deprecated.proto";
import "index_file.proto"; // for IndexFilePropsV2

message PackProperty {
    // when gc_safe_point exceed this version, there must be some data obsolete in this pack
    required uint64 gc_hint_version = 1;
    // effective rows(multiple versions of one row is count as one include delete)
    required uint64 num_rows = 2;
    // the number of rows in this pack which are deleted
    optional uint64 deleted_rows = 3;
}

message PackProperties {
    repeated PackProperty property = 1;
}

message EmbeddedChecksum {
    required string name = 1;
    required bytes checksum = 2;
}

message ChecksumDebugInfo {
    required string name = 1;
    required string content = 2;
}

message ChecksumConfig {
    required uint64 checksum_algorithm = 1;
    required uint64 checksum_frame_length = 2;
    repeated EmbeddedChecksum embedded_checksum = 3;
    // checksum of the above field
    required bytes data_field_checksum = 4;
    // additional information
    repeated ChecksumDebugInfo debug_info = 5;
}

message ColumnStat {
    optional int64 col_id = 1;
    optional string type_name = 2;
    optional double avg_size = 3;
    optional uint64 serialized_bytes = 4;
    optional uint64 data_bytes = 5;
    optional uint64 mark_bytes = 6;
    optional uint64 nullmap_data_bytes = 7;
    optional uint64 nullmap_mark_bytes = 8;
    optional uint64 index_bytes = 9;
    optional uint64 array_sizes_bytes = 10;
    optional uint64 array_sizes_mark_bytes = 11;

    // Only used in tests. Modifying other fields of ColumnStat is hard.
    optional string additional_data_for_test = 101;
    optional VectorIndexFilePropsV1Deprecated deprecated_vector_index = 102; // deprecated. See field 104.
    repeated VectorIndexFilePropsV1Deprecated deprecated_vector_indexes = 103; // deprecated. See field 104.
    repeated DMFileIndexInfo indexes = 104;
}

message DMFileIndexInfo {
    // Currently it only contains nothing more than IndexFilePropsV2.
    // However let's keep using this standalone message, because IndexFilePropsV2
    // is also used by ColumnFile and there could be possibly something only
    // needed by DMFile but not needed by ColumnFile.

    optional IndexFilePropsV2 index_props = 1;
}

message ColumnStats {
    repeated ColumnStat column_stats = 1;
}

message StableFile {
    optional uint64 page_id = 1;
    optional uint64 meta_version = 2;
}

message StableLayerMeta {
    optional uint64 valid_rows = 1;
    optional uint64 valid_bytes = 2;
    repeated StableFile files = 3;
}
