syntax = "proto3";

package activity;

option go_package = "github.com/echofi-ai/backend/types/activity";

import "google/protobuf/timestamp.proto";

// ListeningSession message represents an active listening session
message ListeningSession {
  // Session ID
  string id = 1;

  // User ID
  string user_id = 2;

  // Track ID currently being played
  int32 track_id = 3;

  // Session start time (Unix timestamp in seconds)
  int64 start_time = 4;

  // Session end time (Unix timestamp in seconds, 0 = not set)
  int64 end_time = 5;

  // Last play time (Unix timestamp in seconds, 0 = not set)
  int64 last_play_time = 6;

  // Total playing duration in seconds
  int64 duration = 7;

  // Session status
  string status = 8;

  // Processing timestamp
  optional google.protobuf.Timestamp processed_at = 9;

  // Creation timestamp
  google.protobuf.Timestamp created_at = 10;

  // Last update timestamp
  google.protobuf.Timestamp updated_at = 11;
}

// ConnectionInfo represents a WebSocket connection from a browser tab
message ConnectionInfo {
  // Connection ID (unique per tab/connection)
  string connection_id = 1;

  // User ID
  string user_id = 2;

  // Session ID if this connection has an active session
  optional string session_id = 3;

  // Connection timestamp
  google.protobuf.Timestamp connected_at = 4;

  // Last activity timestamp
  google.protobuf.Timestamp last_activity = 5;

  // Browser tab identifier (optional)
  optional string tab_id = 6;
}

// PointUpdate message for real-time point updates
message PointUpdate {
  // User ID
  string user_id = 1;
  
  // Points earned in this update
  double points_earned = 2;
  
  // Total points for user
  double total_points = 3;
  
  // Current point rate
  double point_rate = 4;
  
  // Update timestamp
  google.protobuf.Timestamp timestamp = 5;
  
  // Session ID
  string session_id = 6;
  
  // Track ID
  int32 track_id = 7;
}

// WebSocket message wrapper for different message types
message WebSocketMessage {
  // Message type
  MessageType type = 1;
  
  // Message payload (one of the following)
  oneof payload {
    PointUpdate point_update = 2;
    SessionUpdate session_update = 3;
    ErrorMessage error = 4;
    HeartbeatMessage heartbeat = 5;
  }
}

// MessageType enum for WebSocket messages
enum MessageType {
  MESSAGE_TYPE_UNSPECIFIED = 0;
  MESSAGE_TYPE_POINT_UPDATE = 1;
  MESSAGE_TYPE_SESSION_UPDATE = 2;
  MESSAGE_TYPE_ERROR = 3;
  MESSAGE_TYPE_HEARTBEAT = 4;
}

// SessionUpdate message for session status changes
message SessionUpdate {
  // Session ID
  string session_id = 1;

  // User ID
  string user_id = 2;

  // Track ID
  int32 track_id = 3;

  // Session status (active, paused, ended) or action (start, pause, end)
  string status = 4;

  // Point rate
  double point_rate = 5;

  // Update timestamp
  google.protobuf.Timestamp timestamp = 6;

  // Number of active connections
  int32 connections = 7;

  // Additional info
  string message = 8;
}

// ErrorMessage for WebSocket errors
message ErrorMessage {
  // Error code
  string code = 1;
  
  // Error message
  string message = 2;
  
  // Timestamp
  google.protobuf.Timestamp timestamp = 3;
}

// HeartbeatMessage for connection health
message HeartbeatMessage {
  // Timestamp
  google.protobuf.Timestamp timestamp = 1;
  
  // Session ID if applicable
  optional string session_id = 2;
}
