// Copyright 2024 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.

// Note: The `required` and `optional` keyword in this file does not make any sense.
// -- For example, a field marked `optional` could be possibly required at the application level.
// The reason why we keep them is to keep the compatibility with the old code.
// Don't introduce required fields any more!!
// New fields should use optional instead.
// See https://protobuf.dev/programming-guides/proto2/

syntax = "proto2";

package dtpb;

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

message ColumnFileBig {
    required uint64 id = 1;
    required uint64 valid_rows = 2;
    required uint64 valid_bytes = 3;
    required uint64 meta_version = 4;
}

message RowKeyRange {
    required bool is_common_handle = 1;
    required uint64 rowkey_column_size = 2;
    required bytes start = 3;
    required bytes end = 4;
}

message ColumnFileDeleteRange {
    required RowKeyRange range = 1;
}

message ColumnSchema {
    required int64 column_id = 1;
    required string column_name = 2;
    required string column_type = 3;
}

message ColumnFileIndexInfo {
    required uint64 index_page_id = 1; // which page it stores
    optional VectorIndexFilePropsV1Deprecated deprecated_vector_index = 2; // deprecated. See field 3.
    optional IndexFilePropsV2 index_props = 3;
}

message ColumnFileTiny {
    repeated ColumnSchema columns = 1;
    required uint64 id = 2;
    required uint64 rows = 3;
    required uint64 bytes = 4;
    repeated ColumnFileIndexInfo indexes = 5;
}

enum ColumnFileType {
    BIG_FILE = 1;
    TINY_FILE = 2;
    DELETE_RANGE = 3;
}

message ColumnFilePersisted {
    required ColumnFileType type = 1;
    oneof file {
        ColumnFileBig big_file = 2;
        ColumnFileTiny tiny_file = 3;
        ColumnFileDeleteRange delete_range = 4;
    }
}

message DeltaLayerMeta {
    repeated ColumnFilePersisted files = 1;
}
