/**
 * Conversation Repository Port Interface
 *
 * Port for inter-agent conversation persistence operations.
 */

import type { Conversation } from '../schema.js';

export interface CreateConversationData {
  fromAgentId: string;
  toAgentId: string;
  initiativeId?: string | null;
  phaseId?: string | null;
  taskId?: string | null;
  question: string;
}

export interface ConversationRepository {
  create(data: CreateConversationData): Promise<Conversation>;
  findById(id: string): Promise<Conversation | null>;
  findPendingForAgent(toAgentId: string): Promise<Conversation[]>;
  answer(id: string, answer: string): Promise<Conversation | null>;

  /**
   * Count conversations grouped by fromAgentId for a batch of agent IDs.
   * Returns only agents that have at least one conversation (count > 0).
   * Used by listForRadar to compute messagesCount without N+1 queries.
   */
  countByFromAgentIds(agentIds: string[]): Promise<{ agentId: string; count: number }[]>;

  /**
   * Find all conversations initiated by a given agent, ordered by createdAt ascending.
   * Used by conversation.getByFromAgent drilldown procedure.
   * Cap at 200 results.
   */
  findByFromAgentId(agentId: string): Promise<Conversation[]>;
}
