import { readFile } from 'node:fs/promises'
import { resolve } from 'node:path'

const root = resolve(new URL('..', import.meta.url).pathname)
const report = JSON.parse(await readFile(resolve(root, 'config/freecad-partdesign-revolution-groove-oracle.json'), 'utf8'))
const fail = (message) => { throw new Error(`FreeCAD PartDesign Revolution/Groove oracle: ${message}`) }
if (report.schemaVersion !== 1 || report.baselineId !== 'freecad-1.1.1-partdesign-revolution-groove-oracle' || report.freecadVersion !== '1.1.1' || report.gitCommit !== '0108fd4b4850cc46e625b60e53cea7a7bbe69f8d' || report.status !== 'pass' || report.summary?.cases !== 2 || report.summary?.passed !== 2 || !Array.isArray(report.cases) || report.cases.length !== 2) fail('baseline or summary is invalid.')
for (const fixture of report.cases) if (!['partdesign-revolution', 'partdesign-groove'].includes(fixture.id) || fixture.passed !== true || fixture.shapeNull !== false || fixture.shapeValid !== true || fixture.solids !== 1 || !(fixture.volume > 0)) fail(`${fixture.id} is not a valid native success fixture.`)
console.log(JSON.stringify({ status: 'freecad-partdesign-revolution-groove-oracle-pass', cases: report.summary.cases, volumes: Object.fromEntries(report.cases.map((fixture) => [fixture.operation, fixture.volume])) }, null, 2))
