/**
 * Resolve the vertical that applies to a memory write.
 *
 * Order of resolution:
 *   1. The write's account-level :LocalBusiness has a non-empty
 *      `businessType` property → vertical = `schema-${businessType}`,
 *      source = `localbusiness-override`.
 *   2. Otherwise → vertical = the brand-declared default, source =
 *      `brand-default`. Brand vertical is `null` for non-vertical brands
 *      (Maxy default), in which case only base rules apply.
 *
 * The Cypher query reads the LocalBusiness anchored at `accountId`. Today's
 * data shape is one LocalBusiness per account; `LIMIT 1` defends against
 * incidental duplicates without claiming to resolve them.
 *
 * Errors propagate — the validator never silently falls back to brand-default
 * on a Neo4j failure. A silent fallback would mask a connectivity problem
 * with a doctrinally-wrong validation outcome.
 */
export async function resolveActiveVertical(params) {
    const { session, accountId, brandVertical } = params;
    const brandDefault = {
        resolvedVertical: brandVertical,
        source: "brand-default",
    };
    if (!accountId || accountId.trim().length === 0) {
        return brandDefault;
    }
    const result = await session.run(`MATCH (lb:LocalBusiness {accountId: $accountId})
     RETURN lb.businessType AS businessType
     LIMIT 1`, { accountId });
    if (result.records.length === 0) {
        return brandDefault;
    }
    const raw = result.records[0].get("businessType");
    if (typeof raw !== "string" || raw.trim().length === 0) {
        return brandDefault;
    }
    return {
        resolvedVertical: `schema-${raw.trim()}`,
        source: "localbusiness-override",
    };
}
//# sourceMappingURL=resolve-active-vertical.js.map