import{OPERATORS as n}from"../../../providers/database/pagination/constants.js";import{isNestedCondition as a}from"../../../providers/database/pagination/utils/is-nested-condition.js";import{isSimpleCondition as f}from"../../../providers/database/pagination/utils/is-simple-condition.js";import{transformCondition as s}from"../../../providers/database/pagination/utils/transform-condition.js";function t(o){if(Array.isArray(o)){if(o.length===0)throw new Error("Entities config cannot be an empty array");if(o.length===1){const r=o[0];if(f(r))return{op:n.AND,conditions:[s(r)]};if(a(r))return{op:n.AND,conditions:[t(r)]};throw new Error("Invalid condition structure")}return{op:n.AND,conditions:o.map(r=>{if(f(r))return s(r);if(a(r))return t(r);throw new Error("Invalid condition structure")})}}const{operator:i,conditions:e}=o;if(!["and","or"].includes(i))throw new Error(`Unsupported operator: ${i}`);const p=Array.isArray(e)?e.map(r=>{if(a(r))return t(r);if(f(r))return s(r);throw new Error("Invalid condition structure")}):[t(e)];return{op:i==="and"?n.AND:n.OR,conditions:p}}export{t as transformEntitiesToFilter};
