import { CONTROLS, GENERATES, STEM_INFO } from './constants'; import type { FiveElement, HeavenlyStemName, Relation, TenGod, } from './types'; export function getElementRelation( dayMaster: FiveElement, other: FiveElement, ): Relation { if (other === dayMaster) return 'companion'; if (GENERATES[other] === dayMaster) return 'resource'; if (GENERATES[dayMaster] === other) return 'output'; if (CONTROLS[dayMaster] === other) return 'wealth'; return 'officer'; } export function isSupportingRelation(relation: Relation): boolean { return relation === 'companion' || relation === 'resource'; } export function getTenGod( dayStem: HeavenlyStemName, otherStem: HeavenlyStemName, ): TenGod { const day = STEM_INFO[dayStem]; const other = STEM_INFO[otherStem]; const relation = getElementRelation(day.element, other.element); const samePolarity = day.yinYang === other.yinYang; switch (relation) { case 'companion': return samePolarity ? '比肩' : '劫财'; case 'resource': return samePolarity ? '偏印' : '正印'; case 'output': return samePolarity ? '食神' : '伤官'; case 'wealth': return samePolarity ? '偏财' : '正财'; case 'officer': return samePolarity ? '七杀' : '正官'; } }