/**
 * Pattern Usage Service
 *
 * Tracks which entities (pages, posts, etc.) use each pattern.
 * Provides sync, query, and count operations for pattern usage tracking.
 *
 * @module PatternUsageService
 */
import type { BlockInstance } from '../../types/blocks';
import type { PatternReference } from '../../types/pattern-reference';
export interface PatternUsage {
    id: string;
    patternId: string;
    entityType: string;
    entityId: string;
    teamId: string;
    createdAt: string;
}
export interface PatternUsageWithEntityInfo extends PatternUsage {
    entityTitle?: string;
    entityName?: string;
    entityFirstName?: string;
    entityLastName?: string;
    entityEmail?: string;
    entitySlug?: string;
    entityStatus?: string;
    entityUpdatedAt?: string;
}
export interface PatternUsageCount {
    entityType: string;
    count: number;
}
export interface GetUsagesOptions {
    entityType?: string;
    limit?: number;
    offset?: number;
}
export interface GetUsagesResult {
    usages: PatternUsageWithEntityInfo[];
    counts: PatternUsageCount[];
    total: number;
}
export declare class PatternUsageService {
    /**
     * Sync pattern usages for an entity
     *
     * Extracts pattern references from blocks and updates the usage table.
     * Uses diff-based approach: only adds new and removes old references.
     *
     * @param entityType - Type of entity (e.g., 'pages', 'posts')
     * @param entityId - ID of the entity
     * @param teamId - Team ID for isolation
     * @param blocks - Array of blocks that may contain pattern references
     * @param userId - User ID for RLS
     */
    static syncUsages(entityType: string, entityId: string, teamId: string, blocks: (BlockInstance | PatternReference)[], userId: string): Promise<void>;
    /**
     * Remove all usages for an entity (on delete)
     *
     * @param entityType - Type of entity
     * @param entityId - ID of the entity
     * @param userId - User ID for RLS
     */
    static removeEntityUsages(entityType: string, entityId: string, userId: string): Promise<void>;
    /**
     * Get usage count for a pattern
     *
     * @param patternId - Pattern ID
     * @param userId - User ID for RLS
     * @returns Total usage count
     */
    static getUsageCount(patternId: string, userId: string): Promise<number>;
    /**
     * Get usage counts grouped by entity type
     *
     * @param patternId - Pattern ID
     * @param userId - User ID for RLS
     * @returns Array of counts by entity type
     */
    static getUsageCounts(patternId: string, userId: string): Promise<PatternUsageCount[]>;
    /**
     * Get detailed usages with entity information
     *
     * Joins with entity tables to get title, slug, status, etc.
     *
     * @param patternId - Pattern ID
     * @param userId - User ID for RLS
     * @param options - Filtering and pagination options
     * @returns Usages with entity info, counts, and total
     */
    static getUsagesWithEntityInfo(patternId: string, userId: string, options?: GetUsagesOptions): Promise<GetUsagesResult>;
    /**
     * Enrich usages with entity information
     *
     * Batches queries by entity type for efficiency.
     *
     * @param usages - Array of pattern usages
     * @param userId - User ID for RLS
     * @returns Usages with entity info added
     */
    private static enrichUsagesWithEntityInfo;
    /**
     * Get all pattern IDs that have usages
     * Useful for checking if any patterns are in use before bulk operations
     *
     * @param patternIds - Array of pattern IDs to check
     * @param userId - User ID for RLS
     * @returns Array of pattern IDs that have at least one usage
     */
    static getPatternsWithUsages(patternIds: string[], userId: string): Promise<string[]>;
    /**
     * Validate which pattern IDs exist in the database
     *
     * Returns only the IDs that exist and are accessible.
     * Used for lazy cleanup - filtering orphaned pattern references on entity save.
     *
     * @param patternIds - Array of pattern IDs to check
     * @param userId - User ID for RLS
     * @returns Set of pattern IDs that exist
     */
    static getExistingPatternIds(patternIds: string[], userId: string): Promise<Set<string>>;
}
//# sourceMappingURL=pattern-usage.service.d.ts.map