import { isStatGroupDesc, StatGroupDesc, StatsType, } from "../../../statistiques/v2/desc/StatsDesc"; import { createStatListItemBlock } from "./createStatListItemBlock"; import { BulletedListItemBlockObjectRequest } from "../blocks/BulletedListItemBlockObjectRequest"; import { BulletedListItemChildren } from "../blocks/BulletedListItemChildren"; export function createStatGroupListItemBlock( descriptor: D, stats: StatsType ): BulletedListItemBlockObjectRequest { return { bulleted_list_item: { rich_text: [ { text: { content: descriptor.label, }, }, ], children: createStatGroupChildrenListItemBlock( descriptor, stats ) as BulletedListItemChildren, }, }; } export function createStatGroupChildrenListItemBlock( descriptor: D, stats: StatsType ): BulletedListItemBlockObjectRequest[] { return Object.keys(descriptor.stats).map((statName) => { const childStatDesc = descriptor.stats[statName]; const childStatValue = stats[statName]; return isStatGroupDesc(childStatDesc) ? createStatGroupListItemBlock( childStatDesc, childStatValue as StatsType ) : createStatListItemBlock(childStatDesc, childStatValue as number); }); }