syntax = 'proto3';

package v1alpha1;

// Cache represents the metadata of a cache managed by cache pool manager.
message Cache {
    // Type represents the type of cache pool manager
    string type = 1;
    // ID represents the id of the cache and the id is unique in the same type of cache
    string ID = 2;
    // SavePath represents the absolute path to store the cache
    string savePath = 3;
    // Parent represents the parent cache of the current cache, if do not have a parent the value is nil
    Cache parent = 4;
    // Size represents the size in bytes of the cache
    int64 size = 5;
    // Created represents the creation time of the cache which is the number of seconds elapsed since January 1, 1970 UTC
    int64 created = 6;
}

// CachePoolManager represents a cache pool manager.
service CachePoolManager {
    // GetCache represents get the specified cache metadata
    rpc GetCache(GetCacheRequest) returns (GetCacheResponse) {}
    // SaveCache represents save the data to a cache directory and record the cache metadata
    rpc SaveCache(SaveCacheRequest) returns (SaveCacheResponse) {}
    // ListCache represents list part of or all of the cache metadata
    rpc ListCache(ListCacheRequest) returns (ListCacheResponse) {}
    // DeleteCache represents delete the specified cached data and remove the corresponding cache metadata
    rpc DeleteCache(DeleteCacheRequest) returns (DeleteCacheResponse) {}
    // LoadCache represents load the specified cache data to work directory
    rpc LoadCache(LoadCacheRequest) returns (LoadCacheResponse) {}
}

// GetCacheRequest
message GetCacheRequest {
    // Type represents the type of cache pool manager
    string type = 1;
    // ID represents the id of the cache
    string ID = 2;
}

message GetCacheResponse {
    // Cache represents the response cache metadata
    Cache cache = 1;
}

message SaveCacheRequest {
    // Cache represents the cache metadata needs to be saved
    Cache cache = 1;
    // SourcePath represents the absolute path of source cache data
    string sourcePath = 2;
}

message SaveCacheResponse {
    // Ok represents whether the cache is saved successfully
    bool ok = 1;
}

message ListCacheRequest {
    // Type represents the type of cache pool manager
    string type = 1;
    // LastCacheID represents the id of the last cache metadata in the most recent query list,
    // if the value is "", query the cache metadata from the starting point of DB,
    // otherwise query the cache metadata starting from the next id of `lastCacheID` in alphabetical order
    string lastCacheID = 2;
    // Limit represents the maximum number of queried entries
    int32 limit = 3;
}
message ListCacheResponse {
    // Caches represents the list of response caches
    repeated Cache caches = 1;
}

message DeleteCacheRequest {
    // Type represents the type of cache pool manager
    string type = 1;
    // ID represents the id of the cache
    string ID = 2;
}
message DeleteCacheResponse {
    // Ok represents whether the cache is deleted successfully
    bool ok = 1;
}

message LoadCacheRequest {
    // Type represents the type of cache pool manager
    string type = 1;
    // ID represents the id of the cache
    string ID = 3;
    // TargetPath represents the work directory for loading the cache data
    string targetPath = 4;
}
message LoadCacheResponse {
    // Ok represents whether the cache is loaded successfully
    bool ok = 1;
}