import type { CrystallizeRichTextCodeNodes } from './code';
import type { CrystallizeRichTextHeadingNodes } from './headings';
import type { CrystallizeRichTextLinkNode } from './link';
import type { CrystallizeRichTextTableNodes } from './table';

export type { CrystallizeRichTextCodeNodes } from './code';
export type { CrystallizeRichTextHeadingNodes } from './headings';

export type CrystallizeRichText = CrystallizeRichTextNode[];

type CrystallizeRichTextNodeBase = {
  textContent?: string;
  children?: CrystallizeRichTextNode[];
  metadata?: Record<string, unknown>;
};

type CrystallizeRichTextParagraphNode = {
  type: 'paragraph';
  kind: 'block';
};

type CrystallizeRichTextHorizontalLineNode = {
  type: 'horizontal-line';
  kind: 'block';
};

type CrystallizeRichTextGenericNode = {
  kind: 'block' | 'inline';
  type?:
    | null
    | 'abbrevition'
    | 'address'
    | 'article'
    | 'aside'
    | 'container'
    | 'details'
    | 'figcaption'
    | 'figure'
    | 'image'
    | 'line-break'
    | 'unordered-list'
    | 'ordered-list'
    | 'list-item'
    | 'picture'
    | 'preformatted'
    | 'quote'
    | 'section'
    | 'time'
    | 'title-of-a-work';
};

export type CrystallizeRichTextInlineFormattedNodes = {
  kind: 'inline';
  type: 'deleted' | 'strong' | 'subscripted' | 'superscripted' | 'underlined' | 'emphasized' | 'code' | 'highlight';
};

export type CrystallizeRichTextNode = CrystallizeRichTextNodeBase &
  (
    | CrystallizeRichTextParagraphNode
    | CrystallizeRichTextHeadingNodes
    | CrystallizeRichTextCodeNodes
    | CrystallizeRichTextGenericNode
    | CrystallizeRichTextLinkNode
    | CrystallizeRichTextTableNodes
    | CrystallizeRichTextHorizontalLineNode
    | CrystallizeRichTextInlineFormattedNodes
  );
