syntax = "proto3";

import "google/protobuf/struct.proto";
import "google/protobuf/any.proto";

package swanlab.proto.record.v1;

option go_package = "core/pkg/pb";

// Record is the base record type in swanlab.
// It is used to represent any kind of record in swanlab.
message Record{
  // Marks the type of the record.
  enum RecordType{
    RECORD_UNKNOWN = 0; // Unknown record type, used for error handling
    RECORD_SETUP = 1;
    RECORD_TEARDOWN = 2;
    RECORD_RUNTIME = 3;
    RECORD_COLUMN = 4;
    RECORD_MEDIA = 5;
    RECORD_SCALAR = 6;
    RECORD_LOG = 7;
  }
  RecordType message_type = 1;
  // The data of this record, it can be any type of data.
  google.protobuf.Any payload = 2;
}


// SetupRecord is a record containing information about the setup process in swanlab.
message SetupRecord{
  // The name of the project
  string name = 1;
  // The workspace of the project, if workspace is empty, it means user not set workspace.
  string workspace = 2;
  // The visibility of the project
  enum Visibility {
    VISIBILITY_UNKNOWN = 0; // Unknown visibility, it means the visibility is not set.
    VISIBILITY_PRIVATE = 1; // Private project
    VISIBILITY_PUBLIC = 2; // Public project
  }
  Visibility visibility = 3;
  // The experiment name, if experiment_name is empty, it means user not set experiment name.
  string experiment_name = 4;
  // The experiment description, if experiment_description is empty, it means user not set experiment description.
  string experiment_description = 5;
  // The experiment tags
  repeated string experiment_tags = 6;
  // The experiment start time
  string start_time = 7;
}

// TeardownRecord is a record containing information about the teardown process in swanlab.
// It may not exist if the process was killed or terminated unexpectedly.
message TeardownRecord{
  // The error message if the teardown process failed
  // if err_message is empty, it means the teardown process was successful
  string error_message = 2;
  // The time when the teardown process was completed
  string end_time = 3;
}


// RuntimeRecord is the record that contains information about the runtime environment of swanlab.
message RuntimeRecord{
  // The conda environment file name
  optional string conda_filename = 1;
  // The pip requirements file name
  optional string pip_filename = 2;
  // The user config file name
  optional string config_filename = 3;
  // The swanlab automatically generated file name, meaning the metadata of the runtime environment.
  optional string metadata_filename = 4;
}

message Range {
  optional int64 minval = 1;
  optional int64 maxval = 2;
}

// ColumnRecord is the type record for each metric in swanlab.
message ColumnRecord{
  // Column ID
  string column_key = 1;
  // Column name
  string column_name = 2;
  // Column class, such as "CUSTOM", "SYSTEM"
  enum ColumnClass{
    COL_CLASS_CUSTOM = 0 ; // Custom column, user-defined, default
    COL_CLASS_SYSTEM = 2 ; // System column, swanlab predefined
  }
  ColumnClass column_class = 3;
  // Column type, such as "FLOAT", "IMAGE".
  enum ColumnType {
    COL_UNKNOWN = 0;  // Unknown column type, used for error handling
    COL_FLOAT = 1;
    COL_IMAGE = 2;
    COL_AUDIO = 3;
    COL_TEXT = 4;
    COL_OBJECT3D = 5;
    COL_MOLECULE = 6;
    COL_ECHARTS = 7;
  }
  ColumnType column_type = 4;
  // If the column is error, a json object
  google.protobuf.Struct column_error = 5;
  // Section name, such as "train", "test", "valid", "eval", etc.
  string section_name = 6;
  // Section type, used to distinguish the section type of the chart.
  enum SectionType {
    SEC_PUBLIC = 0;  // Public section, default
    SEC_SYSTEM = 1;
    SEC_CUSTOM = 2;
    SEC_PINNED = 3;
    SEC_HIDDEN = 4;
  }
  SectionType section_type = 7;
  // The chart name
  string chart_name = 8;
  // The chart index, cuid
  string chart_index = 9;
  // The Y axis range
  Range chart_y_range = 10;
  // The metric name
  string metric_name = 11;
  // The metric color, 2 length hex string, such as "FF0000"
  repeated string metric_color = 12;
}

// MediaRecord is the record generated by swanlab when parsing each piece of media data.
message MediaRecord{
  // record step
  string index = 1;
  // In which row is the data
  string epoch = 2;
  // The time when the record was created
  string create_time = 3;
  // Key name, corresponding column name, same as ColumnRecord.key
  string key = 4;
  // key URL encoded, used to identify the media file
  string key_encoded = 5;
  // Key ID, Backend-Independent, related to the indicator storage directory, the storage path is {run_dir}/{kid}/{file_name}.
  string kid = 6;
  // file name(s)
  repeated string data = 7;
  // more attributes, corresponding to the data, {} means no more attributes
  repeated google.protobuf.Struct more = 8;
}

// ScalarRecord is the record generated by swanlab when parsing each piece of numerical data.
message ScalarRecord{
  // record step
  string index = 1;
  // In which row is the data
  string epoch = 2;
  // The time when the record was created
  string create_time = 3;
  // Key name, corresponding column name
  string key = 4;
  // numerical value
  repeated float data = 5;
}

// LogRecord is the record generated by swanlab when parsing each piece of terminal log data.
message LogRecord{
  // In which row is the data
  string epoch = 1;

  // Log level enum
  enum LogType {
    LOG_INFO = 0;  // Informational log, default
    LOG_WARN = 2;
    LOG_ERROR = 3;
  }
  // Log level
  LogType level = 2;

  // Log message
  string message = 3;
}
