syntax = "proto3";

package task;

option go_package = "github.com/echofi-ai/schema/v2/types/task";

// TaskType represents the type of task repetition
enum TaskType {
  TASK_TYPE_UNSPECIFIED = 0;
  TASK_TYPE_ONE_TIME = 1;  // Can only be completed once per user
  TASK_TYPE_DAILY = 2;     // Reset daily with expiration time
}

// TaskVerificationType represents how task completion is verified
enum TaskVerificationType {
  TASK_VERIFICATION_TYPE_UNSPECIFIED = 0;
  TASK_VERIFICATION_TYPE_BOOLEAN = 1;   // Simple true/false completion
  TASK_VERIFICATION_TYPE_PROGRESS = 2;  // Track current_items/total_items
}

// Task message represents a task definition
message Task {
  // Task ID (unique identifier)
  string id = 1;

  // Task name
  string name = 2;

  // Task description
  string description = 3;

  // Type of task (one-time or daily)
  TaskType task_type = 4;

  // How task completion is verified
  TaskVerificationType verification_type = 5;

  // Total items required for progress tasks (optional)
  optional int32 total_items = 6;

  // Type of items being tracked (e.g., "songs", "minutes")
  optional string item_type = 7;

  // Points awarded for completion
  int32 reward_points = 8;

  // Hours until expiration for daily tasks (optional)
  optional int32 expiration_hours = 9;

  // Whether the task is active
  bool is_active = 10;

  // Creation timestamp (Unix seconds)
  int64 created_at = 11;

  // Last update timestamp (Unix seconds)
  int64 updated_at = 12;
}

// UserTask message represents a user's progress/completion status for a task
message UserTask {
  // User task ID
  int64 id = 1;

  // User ID
  string user_id = 2;

  // Task ID
  string task_id = 3;

  // Current progress for progress tasks
  int32 current_items = 4;

  // Whether the task is completed
  bool is_completed = 5;

  // Whether the reward has been claimed
  bool is_claimed = 6;

  // Completion timestamp (Unix seconds, 0 = not completed)
  int64 completed_at = 7;

  // Claim timestamp (Unix seconds, 0 = not claimed)
  int64 claimed_at = 8;

  // Expiration timestamp for daily tasks (Unix seconds, 0 = no expiration)
  int64 expires_at = 9;

  // Creation timestamp (Unix seconds)
  int64 created_at = 10;

  // Last update timestamp (Unix seconds)
  int64 updated_at = 11;

  // Associated task details (optional, populated when needed)
  optional Task task = 12;
}

// TaskWithUserProgress combines task definition with user's progress
message TaskWithUserProgress {
  // Task definition
  Task task = 1;

  // User's progress (null if user hasn't started this task)
  optional UserTask user_task = 2;

  // Whether the task can be claimed by the user
  bool can_be_claimed = 3;

  // Whether the task has expired (for daily tasks)
  bool is_expired = 4;
}
