/**
 * Type definitions for AI-generated MVP Plan
 * Based on the Vibn MVP Planner agent spec
 */

// Project-level
export type Project = {
  id: string;
  ownerUserId: string;
  name: string;
  createdAt: string;
  updatedAt: string;
  summary: string; // final summary text from planner
};

// Raw vision answers
export type VisionInput = {
  projectId: string;
  q1_who_and_problem: string;
  q2_story: string;
  q3_improvement: string;
  createdAt: string;
};

// Optional work-to-date summary
export type WorkToDate = {
  projectId: string;
  codeSummary?: string;
  githubSummary?: string;
  docsLinksOrText?: string[]; // or JSON
  existingAssetsNotes?: string;
  createdAt: string;
};

// Trees (Journey / Touchpoints / System)
export type TreeType = "journey" | "touchpoints" | "system";

export type Tree = {
  id: string;
  projectId: string;
  type: TreeType;
  label: string;
  createdAt: string;
  updatedAt: string;
};

// Asset types from agent spec
export type AssetType =
  | "web_page"
  | "app_screen"
  | "flow"
  | "component"
  | "email"
  | "notification"
  | "document"
  | "social_post"
  | "data_model"
  | "api_endpoint"
  | "service"
  | "integration"
  | "job"
  | "infrastructure"
  | "automation"
  | "other";

// Each node in any tree
export type AssetNode = {
  id: string;
  projectId: string;
  treeId: string;
  parentId: string | null;
  name: string;
  assetType: AssetType;
  mustHaveForV1: boolean;
  createdAt: string;
  updatedAt: string;
  children?: AssetNode[]; // For nested structure
};

// Node metadata (reasoning, mapping back to vision)
export type AssetMetadata = {
  assetNodeId: string;
  whyItExists: string;
  whichUserItServes?: string;
  problemItHelpsWith?: string;
  connectionToMagicMoment: string;
  valueContribution?: string;
  journeyStage?: string;
  messagingTone?: string;
  visualStyleNotes?: string;
  dependencies?: string[]; // other AssetNode IDs
  implementationNotes?: string;
};

// Context memory events
export type ContextEvent = {
  id: string;
  projectId: string;
  sourceType: "chat" | "commit" | "file" | "doc" | "manual_note";
  sourceId?: string; // e.g. commit hash, file path
  timestamp: string;
  title: string;
  body: string; // raw text or JSON
};

// Full AI response from agent
export type AIAgentResponse = {
  journey_tree: {
    label: string;
    nodes: Array<AssetNode & { asset_metadata: AssetMetadata }>;
  };
  touchpoints_tree: {
    label: string;
    nodes: Array<AssetNode & { asset_metadata: AssetMetadata }>;
  };
  system_tree: {
    label: string;
    nodes: Array<AssetNode & { asset_metadata: AssetMetadata }>;
  };
  summary: string;
};

