syntax = "proto3";

package db;

import "repos/protobuf/gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "lib/protocol/bep.proto";
import "ext.proto";

message FileVersion {
    protocol.Vector version         = 1;
    bool            deleted         = 2;
    repeated bytes  devices         = 3;
    repeated bytes  invalid_devices = 4;
}

message VersionList {
    option (gogoproto.goproto_stringer) = false;
    repeated FileVersion versions = 1 [(ext.goname) = "RawVersions"];
}

// Must be the same as FileInfo but without the blocks field
message FileInfoTruncated {
    option (gogoproto.goproto_stringer) = false;
    string                name           = 1;
    int64                 size           = 3;
    int64                 modified_s     = 5;
    uint64                modified_by    = 12 [(ext.gotype) = "github.com/syncthing/syncthing/lib/protocol.ShortID"];
    protocol.Vector       version        = 9;
    int64                 sequence       = 10;
    // repeated BlockInfo Blocks         = 16
    string                symlink_target = 17;
    bytes                 blocks_hash    = 18;
    bytes                 encrypted      = 19;
    protocol.FileInfoType type           = 2;
    uint32                permissions    = 4;
    int32                 modified_ns    = 11;
    int32                 block_size     = 13 [(ext.goname) = "RawBlockSize"];

    // see bep.proto
    uint32 local_flags  = 1000;
    bytes  version_hash = 1001;

    bool deleted        = 6;
    bool invalid        = 7 [(ext.goname) = "RawInvalid"];
    bool no_permissions = 8;
}

// BlockList is the structure used to store block lists
message BlockList {
    repeated protocol.BlockInfo blocks = 1;
}

// IndirectionHashesOnly is used to only unmarshal the indirection hashes
// from a FileInfo
message IndirectionHashesOnly {
    bytes blocks_hash  = 18;
    bytes version_hash = 1001;
}

// For each folder and device we keep one of these to track the current
// counts and sequence. We also keep one for the global state of the folder.
message Counts {
    option (gogoproto.goproto_stringer) = false;

    int32  files       = 1;
    int32  directories = 2;
    int32  symlinks    = 3;
    int32  deleted     = 4;
    int64  bytes       = 5;
    int64  sequence    = 6; // zero for the global state
    bytes  device_id   = 17 [(ext.goname) = "DeviceID"]; // device ID for remote devices, or special values for local/global
    uint32 local_flags = 18; // the local flag for this count bucket
}

message CountsSet {
    repeated Counts counts  = 1;
    int64           created = 2; // unix nanos
}

message FileVersionDeprecated {
    protocol.Vector version = 1;
    bytes           device  = 2;
    bool            invalid = 3;
    bool            deleted = 4;
}

message VersionListDeprecated {
    option (gogoproto.goproto_stringer) = false;
    repeated FileVersionDeprecated versions = 1;
}

message ObservedFolder {
    google.protobuf.Timestamp time              = 1 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
    string                    label             = 2;
    bool                      receive_encrypted = 3;
    bool                      remote_encrypted  = 4;
}

message ObservedDevice {
    google.protobuf.Timestamp time    = 1 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
    string                    name    = 2;
    string                    address = 3;
}
