#!/usr/bin/env node
import*as r from'fs';import*as c from'path';import*as d from'js-yaml';var u=".paradigm/decisions";function y(){let t=new Date().toISOString().slice(0,10),n=String(Math.floor(Math.random()*999)+1).padStart(3,"0");return `TD-${t}-${n}`}function D(o,t){let n=new Date,a=y(),s={id:a,timestamp:n.toISOString(),...t},e=c.join(o,u);r.mkdirSync(e,{recursive:true});let i=c.join(e,`${a}.yaml`);return r.writeFileSync(i,d.dump(s,{lineWidth:120,noRefs:true}),"utf8"),s}function g(o,t,n){let a=f(o,t);if(!a)return null;let s={...a,...n},e=c.join(o,u),i=c.join(e,`${t}.yaml`);return r.writeFileSync(i,d.dump(s,{lineWidth:120,noRefs:true}),"utf8"),s}function h(o,t,n){if(!f(o,t))return null;let s=D(o,n),e=g(o,t,{status:"superseded",superseded_by:s.id});return e?{old:e,new:s}:null}function p(o,t){let n=c.join(o,u);if(!r.existsSync(n))return [];let a=[],s=r.readdirSync(n).filter(i=>i.endsWith(".yaml"));for(let i of s)try{let m=r.readFileSync(c.join(n,i),"utf8"),l=d.load(m);l&&l.id&&a.push(l);}catch{}let e=a;return t?.status&&(e=e.filter(i=>i.status===t.status)),t?.participant&&(e=e.filter(i=>i.participants.some(m=>m.id===t.participant))),t?.symbol&&(e=e.filter(i=>i.symbols_affected?.includes(t.symbol))),t?.tag&&(e=e.filter(i=>i.tags?.some(m=>m.startsWith(t.tag)))),t?.dateFrom&&(e=e.filter(i=>i.timestamp>=t.dateFrom)),t?.dateTo&&(e=e.filter(i=>i.timestamp<=t.dateTo)),e.sort((i,m)=>m.timestamp.localeCompare(i.timestamp)),t?.limit&&(e=e.slice(0,t.limit)),e}function f(o,t){let n=c.join(o,u),a=c.join(n,`${t}.yaml`);if(!r.existsSync(a))return null;let s=r.readFileSync(a,"utf8");return d.load(s)}function S(o,t){return p(o,{symbol:t,status:"active"})}function T(o){let t=p(o),n={},a=new Set;for(let s of t)n[s.status]=(n[s.status]||0)+1,s.symbols_affected?.forEach(e=>a.add(e));return {total:t.length,active:n.active||0,superseded:n.superseded||0,deprecated:n.deprecated||0,proposed:n.proposed||0,recentDecisions:t.slice(0,10).map(s=>({id:s.id,title:s.title,status:s.status,timestamp:s.timestamp})),symbolsCovered:[...a].sort()}}export{D as a,g as b,h as c,p as d,f as e,S as f,T as g};