import { bool, childScope, has, intIn, makeParser, monthDay, report, } from './parse-helpers'; import { AUTOPILOT_RULE_IDS, type SeasonAutopilotConfig, } from './rule-config.types'; export const DEFAULT_SEASON_AUTOPILOT_CONFIG: SeasonAutopilotConfig = { honeySuperMinFrames: 8, varroaMeasureIntervalDays: 28, winterVarroaWindow: { from: '11-15', to: '12-20' }, queenMaxAgeYears: 2, suggestionTtlDays: 30, maxStepsPerColony: 3, rules: { A1: true, A2: true, A3: true, A4: true, A5: true, A6: true, A7: true, A8: true, A9: true, A10: true, }, }; export const seasonAutopilotParser = makeParser( 'SEASON_AUTOPILOT', DEFAULT_SEASON_AUTOPILOT_CONFIG, (scope) => { const d = DEFAULT_SEASON_AUTOPILOT_CONFIG; const windowScope = childScope(scope, 'winterVarroaWindow'); let winterVarroaWindow = { from: monthDay(windowScope, 'from', d.winterVarroaWindow.from), to: monthDay(windowScope, 'to', d.winterVarroaWindow.to), }; if (winterVarroaWindow.from > winterVarroaWindow.to) { report( windowScope, has(windowScope, 'from') ? 'from' : 'to', 'Das Fenster muss innerhalb eines Jahres liegen: Beginn vor Ende.', ); winterVarroaWindow = { ...d.winterVarroaWindow }; } const ruleScope = childScope(scope, 'rules'); const rules = { ...d.rules }; for (const id of AUTOPILOT_RULE_IDS) { rules[id] = bool(ruleScope, id, d.rules[id]); } return { honeySuperMinFrames: intIn( scope, 'honeySuperMinFrames', d.honeySuperMinFrames, 1, 40, ), varroaMeasureIntervalDays: intIn( scope, 'varroaMeasureIntervalDays', d.varroaMeasureIntervalDays, 7, 90, ), winterVarroaWindow, queenMaxAgeYears: intIn( scope, 'queenMaxAgeYears', d.queenMaxAgeYears, 1, 10, ), suggestionTtlDays: intIn( scope, 'suggestionTtlDays', d.suggestionTtlDays, 1, 365, ), maxStepsPerColony: intIn( scope, 'maxStepsPerColony', d.maxStepsPerColony, 1, 3, ), rules, }; }, );