syntax = "proto2";
import "machinetalk/protobuf/nanopb.proto";

// see README.msgid
// msgid base: 200

package machinetalk;

enum ApplicationType {
    QT5_QML    = 1;
    GLADEVCP   = 2;
    JAVASCRIPT = 3;
}

enum FileContent {
    CLEARTEXT  = 1;
    ZLIB       = 2;
};

message File {

    option (nanopb_msgopt).msgid = 200; // see README.msgid

    required string       name          = 1;                       // file name or path, flat for now
    optional FileContent  encoding      = 2 [default = CLEARTEXT]; // file encoding
    optional bytes        blob          = 3 [default = ""];        // file data
    optional uint32       size          = 4 [default = 0];         // file size
    optional bool         is_dir        = 5 [default = false];     // indicates if file is actually a directo
    optional uint64       last_modified = 6 [default = 0];         // timestamp of last modification
}

message Application {

    option (nanopb_msgopt).msgid = 201;

    required string       name          = 1; // unique key
    optional string       description   = 2; // comment
    optional ApplicationType type       = 3;
    optional string       weburi        = 4; // for type == JAVASCRIPT

    repeated File         file          = 5;
    // config params go here
}

message StdoutLine {

    option (nanopb_msgopt).msgid = 202;

    required int32  index = 1;
    optional string line  = 2;
}

message MachineInfo {

    option (nanopb_msgopt).msgid = 203;

    optional string     type            = 1; // type of the machine, e.g. FDM, CNC, ...
    optional string     manufacturer    = 2; // manufacturer of the machine
    optional string     model           = 3; // machine model
    optional string     variant         = 4; // variant of the machine
}

// message for mklauncher
message Launcher {

    option (nanopb_msgopt).msgid = 204;

    required int32        index          = 1;  // index is necessary to access repeated
    optional string       name           = 2;  // visible name
    optional string       description    = 3;  // description of the config
    optional File         image          = 4;  // image representing the configuration
    optional MachineInfo  info           = 5;  // information about the machine

    optional bool         running        = 6;  // indicates whether the config is running or not
    optional bool         terminating    = 7;  // indicates if a terminations signal was sent to the process
    optional string       command        = 8;  // configuration start command
    optional bool         shell          = 9;  // if the configuration command is executed in a shell
    repeated StdoutLine   output         = 10; // stdout output of the command
    optional int32        returncode     = 11; // return code of the command
    optional string       workdir        = 12; // working dir of the command
    optional uint32       priority       = 13; // priority for sorting, smaller means lower priority
    optional uint32       importance     = 14; // importance set by the user, smaller means less important
}

// message for file service
message FileServiceData {
    repeated File  files           = 1; // list of files
}
