/**
 * Stage 3: STORE
 *
 * Appends enriched feedback events to JSONL storage:
 * 1. Append to daily raw log (immutable)
 * 2. Update in-memory indexes
 * 3. Update rolling aggregates
 *
 * Delegates to the storage package for actual file I/O.
 */

import type { EnrichedFeedbackEvent } from "../types.js";
import type { StorageResult, PipelineConfig } from "./types.js";
import { appendFeedback } from "../storage/feedback-store.js";

/**
 * Store an enriched feedback event to persistent JSONL storage.
 */
export async function storeFeedback(
  event: EnrichedFeedbackEvent,
  config: PipelineConfig
): Promise<StorageResult> {
  try {
    const filePath = await appendFeedback(event, config.dataDir);
    return { success: true, filePath };
  } catch (error) {
    return {
      success: false,
      error: `Storage failed: ${error instanceof Error ? error.message : String(error)}`,
    };
  }
}
