import { type IconInterface } from '@src/types/icons';

export type SidebarArticleStatus = 'enabled' | 'disabled';

/** Minimal article shape consumed by sidebar adapters (API-agnostic). */
export type SidebarArticleLike = {
  id: number;
  title: string;
  icon: IconInterface;
  status: SidebarArticleStatus;
  position: number | null;
  parentId?: number | null;
  children?: SidebarArticleLike[] | null;
  isEditor?: boolean | null;
};

export type SidebarArticleTree = SidebarArticleLike & {
  children: SidebarArticleTree[] | null;
};

/** Normalized domain node — flat adjacency list entry. */
export type SidebarNode = {
  id: number;
  parentId: number | null;
  position: number;
  title: string;
  icon: IconInterface;
  status: SidebarArticleStatus;
  childCount: number;
  depth: number;
  isEditor?: boolean | null;
};

/** Canonical sidebar data contract between consumers and LibrariesSidebar. */
export type SidebarModel = {
  headerTitle: string;
  nodes: readonly SidebarNode[];
};

export type SidebarCapabilities = {
  canCreate: boolean;
  showStatusBadge: boolean;
};

export type SidebarNodeFilterContext = {
  isRoot: boolean;
};

export type SidebarNodePredicate = (
  node: SidebarNode,
  context: SidebarNodeFilterContext,
) => boolean;

export const EMPTY_SIDEBAR_MODEL: SidebarModel = {
  headerTitle: '',
  nodes: [],
};
