/* 3DPrinterOS command request and status report protocol */
/* TODO:    Enumerate errors and remove their codes
            Enumerate commands?
            Unjsonify printer profiles?
*/

syntax = "proto3";

package printeros.printer;

enum CameraType {
    Disable_camera = 0; 
    Dual_camera = 1;
    Multi_camera = 2;
    Pi_camera = 3;
    MP_camera = 4;
}

message ServerError {
    uint32 code = 1;
    string message = 2;
}

message ClientError {
    uint32 code = 1;
    string message = 2;
    enum ErrorLevel {
      info = 0;
      warning = 1;
      error = 2;
    }
    ErrorLevel level = 3;
}

message PrinterUSBInfo {
    string VID = 1;
    string PID = 2;
    string SNR = 3;
    string COM = 4;
    string PHYSICAL_PORT = 5;
    string IP = 6;
}

message PrinterLoginRequest {
    string user_token = 1;
    PrinterUSBInfo printer = 2;
    string client_version = 3;
    string date_time = 4;
    CameraType camera = 5;
    /* string auth_token = 1; */
}

message PrinterLoginAnswer {
    string printer_token = 1;
    string printer_profile = 2;
    string name = 3;
    ServerError error = 4;
    float operational_timeout = 5;
    repeated string groups = 7;
}

message CommandRequest {
    string printer_token = 1;
    enum PrinterState {
       connecting = 0;
       ready = 1;
       printing = 2;
       error = 3;
       downloading = 4;
       paused = 5;
       local_mode = 6;
    }
    PrinterState state = 2;
    message Report {
        uint32 percent = 1;
        uint64 line_number = 2;
        float bed_temp = 3;
        float bed_t_temp = 4;
        float chamber_temp = 5;
        float chamber_t_temp = 6;
        repeated float ext_temps = 7;
        repeated float ext_t_temps = 8;
        repeated float coords = 9;
        string response = 10; /* not used, but need to be removed from the client code first */
    }
    Report report = 3;
    message CommandAcknowledge {
        uint64 number = 1;
        bool result = 2;  
    }
    CommandAcknowledge ack = 4;
    repeated ClientError errors = 5;
    bool reset_job = 6;
    bool reset_printer_type = 7;
    CameraType camera_change = 8;
    string select_printer_type = 9;
    repeated string select_groups = 10;
}

message ServerCommand {
    uint64 number = 1;
    string payload = 2;
    ServerError error = 5; 
    /* commands should be reimplemented without link and zip, as enums in future */
    string command_string = 11;
    bool link = 12;
    bool zip = 13;
}

message ClientMessageWrap {
    uint32 protocol_version = 1;
    string protocol_mod = 2;
    oneof message_type {
        PrinterLoginRequest printer_login_request = 3;
        CommandRequest command_request = 4;
        ClientError error = 15;
    }
}

message ServerMessageWrap {
    oneof message_type {
        PrinterLoginAnswer printer_login = 3;
        ServerCommand server_command = 4;
        ServerError error = 15;
    }
}
