export type IParseResponse<T = {}> = {
  data?: T;
  error?: { message: string };
};

export type IManifestResponse = {
  status: number;
  elapsed: number;
  error?: { message: string };
  manifest?: IManifest;
};

export type IManifest = {
  path: string;
  resources: IManifestResource[];
};

export type IManifestResource =
  | IManifestFolder
  | IManifestFile
  | IManifestImage
  | IManifestMarkdown
  | IManifestJson
  | IManifestYaml;

export type ManifestFileType =
  | IManifestFolder['type']
  | IManifestFile['type']
  | IManifestImage['type']
  | IManifestMarkdown['type']
  | IManifestJson['type']
  | IManifestYaml['type'];

/**
 * Manifest types.
 */
export type IManifestCommon = {
  path: string;
  error?: { message: string };
};

export type IManifestFolder = IManifestCommon & {
  type: 'FOLDER';
};

export type IManifestFile = IManifestCommon & {
  type: 'FILE';
};

export type IManifestImage = IManifestCommon & {
  type: 'FILE/image';
  name: string;
  ext: string;
  path2x?: string;
  width?: number;
  height?: number;
};

export type IManifestMarkdown = IManifestCommon & {
  type: 'FILE/markdown';
  markdown?: IMarkdown;
};

export type IManifestJson = IManifestCommon & {
  type: 'FILE/json';
  data?: { [key: string]: any };
};

export type IManifestYaml = IManifestCommon & {
  type: 'FILE/yaml';
  data?: { [key: string]: any };
};

/**
 * Markdown.
 */
export type IMarkdown = {
  title?: string;
  sections: IMarkdownSection[];
};
export type IMarkdownSection<T = {}> = {
  depth: number;
  heading?: string;
  data: Array<IMarkdownData<T>>;
  html?: string;
};

export type IMarkdownData<T = {}> = {
  value: T;
  meta?: string;
};
