syntax = "proto3";

import "google/protobuf/struct.proto"; // after syntax!

package map;

// ----------------------------
// Map Service
// ----------------------------
service MapService {
    rpc RenderTile(RenderTileRequest) returns (RenderTileOut);
    rpc ClearTile(ClearTileRequest) returns (ClearTileOut);
    rpc ReadDir(ReadDirRequest) returns (ReadDirOut);
    rpc CreateXML(CreateXMLRequest) returns (stream JobProgress); // streaming XML creation
    rpc UploadXML(UploadXMLRequest) returns (UploadXMLOut);
    rpc UploadRaster(UploadRasterRequest) returns (UploadRasterOut);
    rpc GetRasterStatus(GetRasterStatusRequest) returns (GetStatusOut);
    rpc GetStat(GetStatRequest) returns (GetStatOut);
    rpc GetRender(GetRenderRequest) returns (GetRenderOut);
    rpc GetLogs(GetLogsRequest) returns (GetLogsOut);
    rpc GetRasterInfo(GetRasterInfoRequest) returns (GetRasterInfoOut);
}

// ----------------------------
// Messages for MapService
// ----------------------------
message RenderTileRequest {
    string name = 1;
    string path = 2;
    repeated double bbox = 3;  // [minx, miny, maxx, maxy]
    int32 width = 4;
    string ttl = 5; // "5m", "1h", "1d" or "0"
    string debug = 6;
}

message RenderTileOut {
    string base64 = 1;
    bool cache = 2;
    string err = 3;
    string xml_path = 4;
}

message ClearTileRequest {
    string name = 1;
    string path = 2;
}

message ClearTileOut {
    string result = 1;
    string err = 2;
}

message ReadDirRequest {
    string path = 1;
}

message FileInfo {
    string name = 1;
    int64 size = 2;
    string date = 3;
}

message ReadDirOut {
    bool exists = 1;
    int32 count = 2;
    repeated FileInfo files = 3;
}

message CreateXMLRequest {
    string path = 1;
    int32 srid = 2;
    int32 previewZoom = 3;
    repeated string layers = 4;
    bool vrt = 5;
    string name = 6;
    string debug = 7;
    string nocache = 8;
}

message UploadXMLRequest {
    string name = 1;
    string xml = 2;
    string encoding = 3;
}

message UploadXMLOut {
    string status = 1;
    string filepath = 2;
}

message UploadRasterRequest {
    string path = 1;
    bytes data = 2;
    bool chunked = 3;
    int64 filesize = 4;
}

message UploadRasterOut {
    string status = 1;
    int64 uploaded = 2;
    bool finished = 3;
}

message GetRasterStatusRequest {
    string path = 1;
    bool md5 = 2;
}

message GetStatusOut {
  bool exists = 1;
  string size = 2;
  bool finished = 3;
}

message GetStatRequest {
    string period = 1;  // "5m", "1h", "1d"
    string ttl = 2; // "0"
}

message GetStatOut {
    google.protobuf.Struct result = 1; // dynamic json structure, not bound by same value type like with map
}

message GetRenderRequest {
    string name = 1;
    string path = 2;
}

message GetRenderOut {
    string result = 1;  // serialized object or placeholder
}

message GetLogsRequest {
    string path = 1;  // "info", "info/2026-01-01.log" etc.
}

message GetLogsOut {
    string data = 1;
    string links = 2;
    string err = 3;
}

message GetRasterInfoRequest {
    string path = 1;
    string ttl = 2;
    int64 srid = 3;
}

message FileItem {
  string name = 1;
  string size = 2;
}

message GetRasterInfoData {
    string total_size = 1;
    string extension = 2;
    int64 srid = 3;
    string proj4 = 4;
    repeated float extent = 5;
    repeated FileItem files = 6;
    int64 width = 7;
    int64 height = 8;
    int64 bands_count = 9;
    string resolution = 10;
    repeated string bands = 11;
    int64 color_depth = 12;
    string compression = 13;
}

message GetRasterInfoOut {
    GetRasterInfoData data = 1;
    bool cache = 2;
}

// ----------------------------
// Job Service Messages
// ----------------------------
message JobRequest {
    string job_id = 1;
    string xml_name = 2;
    string xml_path = 3;
    repeated string layers = 4;
}

message JobProgress {
    string message = 1;
    string error = 2;
    bool done = 3;
}
