export type TreeProjectionKind = "sidebar_tree" | "page_tree" | "file_tree";

export type WorkspaceSourceKind = "local_folder" | "convex_workspace";

export type WorkspaceSourceCapability =
  | "load-snapshot"
  | "watch"
  | "preflight-command"
  | "execute-command"
  | "resolve-page-aggregate";

export type WorkspaceSource = {
  sourceKind: WorkspaceSourceKind;
  rootUri: string;
  workspaceId: string;
  capabilities: WorkspaceSourceCapability[];
};

export type TreeProjectionNodeType =
  | "workspace"
  | "folder"
  | "page"
  | "section"
  | "asset"
  | "mindmap"
  | "table"
  | "book"
  | "pdf"
  | "index";

export type TreeProjectionCapability =
  | "expand"
  | "open"
  | "drag"
  | "drop"
  | "select"
  | "create-child"
  | "rename"
  | "archive"
  | "restore"
  | "context-menu"
  | "reorder"
  | "open-asset"
  | "pick";

export type TreeProjectionResourceKind =
  | "workspace"
  | "document"
  | "index"
  | "asset"
  | "asset_folder"
  | "mindmap"
  | "table"
  | "book"
  | "pdf";

export type TreeProjectionAssetKind =
  | "file"
  | "mindmap"
  | "table"
  | "book"
  | "pdf"
  | "image"
  | "video"
  | "audio"
  | "unknown";

export type TreeProjectionSourceOperationProfile =
  | "local_readonly"
  | "convex_workspace";

export type TreeProjectionSourceMetadata = {
  sourceKind: WorkspaceSourceKind;
  sourceUri: string;
  relativePath?: string | null;
  storageIdentity?: string | null;
  operationProfile?: TreeProjectionSourceOperationProfile | null;
};

export type TreeProjectionResourceExtra = {
  source?: TreeProjectionSourceMetadata | null;
} & Record<string, unknown>;

export type TreeProjectionResourceMeta = {
  resourceKind: TreeProjectionResourceKind;
  documentId?: string | null;
  assetId?: string | null;
  workspaceId?: string | null;
  assetKind?: TreeProjectionAssetKind | null;
  iconHint?: string | null;
  extra?: TreeProjectionResourceExtra;
};

export type TreeProjectionItemBase = {
  nodeId: string;
  parentNodeId: string | null;
  nodeType: TreeProjectionNodeType;
  projectionKind: TreeProjectionKind;
  title: string;
  depth: number;
  position: number | null;
  childCount: number;
  expandable: boolean;
  expandedByDefault: boolean;
  capabilities: TreeProjectionCapability[];
  resourceMeta: TreeProjectionResourceMeta;
  iconHint: string | null;
};
