import{sql as t}from"drizzle-orm";function E(e,r){if(!e||e.length===0)return;const n=r?`${r}.rbac_teams`:"rbac_teams",a=t.join(e.map(o=>t`${o}`),t`, `);return t`(${t.raw(n)} IS NULL OR json_array_length(COALESCE(${t.raw(n)}, '[]')) = 0 OR EXISTS (SELECT 1 FROM json_each(COALESCE(${t.raw(n)}, '[]')) AS t WHERE t.value IN (${a})))`}function s(e,r){if(!e||e.length===0)return null;const n=r?`${r}.rbac_teams`:"rbac_teams",a=e.map(o=>`'${o.replace(/'/g,"''")}'`).join(", ");return`(${n} IS NULL OR json_array_length(COALESCE(${n}, '[]')) = 0 OR EXISTS (SELECT 1 FROM json_each(COALESCE(${n}, '[]')) AS t WHERE t.value IN (${a})))`}function u(e,r){if(!(e&&e.length>0))return{join:t``,filter:t``};const a=t`LEFT JOIN combined_target_attributes attr ON attr.entity_key = ${t.raw(r??"key")}`,o=t`
              AND (
                attr.rbac_teams IS NULL
                OR json_array_length(attr.rbac_teams) = 0
                OR EXISTS (
                  SELECT 1 FROM json_each(attr.rbac_teams) as t
                  WHERE t.value IN (${t.join(e.map(i=>t`${i}`),t`, `)})
                )
              )`;return{join:a,filter:o}}export{E as buildRbacFilter,s as buildRbacFilterRaw,u as buildSubqueryRbacJoinAndFilter};
