import { Brackets } from "typeorm";
export function shouldHideEUsersFor(viewer) {
    return !!viewer && !viewer.isAdmin && !viewer.isModerator && (viewer.minorBadges ?? []).some((badge)=>badge === "K" || badge === "T");
}
export function generateMinorBadgeUserVisibilityQuery(q, viewer, alias = "user") {
    if (!shouldHideEUsersFor(viewer)) return;
    q.andWhere(new Brackets((qb)=>{
        qb.where(`${alias}.id = :minorBadgeViewerId`).orWhere(`NOT ('E' = ANY(${alias}."minorBadges"))`);
    }));
    q.setParameter("minorBadgeViewerId", viewer.id);
}
export function generateMinorBadgeNoteVisibilityQuery(q, viewer, noteAlias = "note") {
    if (!shouldHideEUsersFor(viewer)) return;
    q.andWhere(new Brackets((qb)=>{
        qb.where(`${noteAlias}."userId" = :minorBadgeViewerId`).orWhere(`${noteAlias}."userId" NOT IN (` + `SELECT "id" FROM "user" WHERE 'E' = ANY("minorBadges")` + `)`);
    }));
    q.setParameter("minorBadgeViewerId", viewer.id);
}
