export interface GoalStats {
  message_count: number;
  total_tokens: number;
  total_cost: number;
  preview?: string;
}

export interface Knowledge {
  id: string;
  scenario: string;
  content: string;
  score?: number;
  quality_score?: number;
  tags?: {
    type?: string[];
  };
  metrics?: {
    helpful?: number;
    harmful?: number;
  };
  created_at?: string;
}

export interface Goal {
  id: string;
  description: string;
  reason?: string;
  status: "pending" | "running" | "completed" | "failed";
  summary?: string;
  parent_id?: string;
  created_at: string;
  completed_at?: string;
  metadata?: Record<string, unknown>;
  agent_call_mode?: string;
  sub_trace_ids?: Array<string | { trace_id: string; mission?: string }>;
  sub_goals?: Array<Goal>;
  self_stats?: GoalStats;
  cumulative_stats?: GoalStats;
  knowledge?: Knowledge[];
}

export interface BranchContext {
  branch_id: string;
  parent_goal_id: string;
  status: string;
  created_at: string;
  completed_at?: string;
}

// ===== Knowledge Feedback Types =====

export interface KnowledgeLogEntry {
  knowledge_id: string;
  goal_id: string;
  injected_at_sequence: number;
  injected_at: string;
  task: string;
  content: string;
  eval_result: {
    eval_status?: string;
    reason?: string;
    score?: number;
  } | null;
  evaluated_at: string | null;
  evaluated_at_trigger?: string | null;
  user_feedback: {
    action: string;
    eval_status?: string;
    feedback_by: string;
    feedback_at: string;
    feedback_text?: string;
  } | null;
}

export type FeedbackAction = "confirm" | "override" | "skip";

export interface KnowledgeFeedbackState {
  action: FeedbackAction;
  eval_status?: string;
  feedback_text?: string;
}
