// @bun
var{defineProperty:G,getOwnPropertyNames:K,getOwnPropertyDescriptor:L}=Object,M=Object.prototype.hasOwnProperty;function N(j){return this[j]}var X=(j)=>{var f=(J??=new WeakMap).get(j),k;if(f)return f;if(f=G({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var z of K(j))if(!M.call(f,z))G(f,z,{get:N.bind(j,z),enumerable:!(k=L(j,z))||k.enumerable})}return J.set(j,f),f},J;var Q=(j)=>j;function S(j,f){this[j]=Q.bind(null,f)}var Y=(j,f)=>{for(var k in f)G(j,k,{get:f[k],enumerable:!0,configurable:!0,set:S.bind(f,k)})};var Z=(j,f)=>()=>(j&&(f=j(j=0)),f);class T{client;options;constructor(j,f){this.client=j;this.options=f}async evaluate(j,f,k){let z=U(j,f,k),E=await this.client.evaluate(this.options.decisionPath,z),F=this.options.mapResult?this.options.mapResult(E):E;if(!F)return{...k,evaluatedBy:k.evaluatedBy??"engine"};let B=F,H=V(f,k.requiredConsents??[],B.requiredConsents??[]);return{...k,effect:B.effect??k.effect,reason:B.reason??k.reason,fieldDecisions:B.fieldDecisions??k.fieldDecisions,requiredConsents:H.length?H:void 0,evaluatedBy:"opa"}}}function U(j,f,k){return{context:j,decision:k,policies:f.map((z)=>({meta:z.meta,rules:z.rules,fieldPolicies:z.fieldPolicies,pii:z.pii,relationships:z.relationships,consents:z.consents,rateLimits:z.rateLimits}))}}function V(j,f,k){if(k.length===0)return f;let z=new Set(f.map((F)=>F.id)),E=[...f];for(let F of k){if(z.has(F))continue;let B=W(j,F);if(B)E.push(B),z.add(B.id)}return E}function W(j,f){for(let k of j){let z=k.consents?.find((E)=>E.id===f);if(z)return z}return{id:f,scope:"unspecified",purpose:"unspecified",description:`Consent "${f}" returned by OPA`,required:!0}}export{U as buildOPAInput,T as OPAPolicyAdapter};
