"""
Duplicate detection for transaction import and manual entry.

flag_duplicates() is shared infrastructure — called from:
  - staging_pipeline.py (Epic 9): detects duplicates across staged + committed transactions
  - transactions blueprint (Story 3.3): warns on manual duplicate entry

Architectural boundary: accepts ONLY plain Python types. No ORM session, no db imports.
The caller is responsible for querying the DB and passing fingerprint strings.
"""
from __future__ import annotations


def flag_duplicates(
    new_fingerprints: list[str],
    existing_fingerprints: list[str],
) -> list[bool]:
    """
    Flag which new fingerprints already exist in the committed/staged set.

    Args:
        new_fingerprints: Dedup hashes for transactions being evaluated.
        existing_fingerprints: Dedup hashes from existing transactions
            (caller queries the DB within a ±3-day window before calling this).

    Returns:
        List[bool] of same length as new_fingerprints.
        True  → this hash exists in existing_fingerprints (probable duplicate).
        False → not found (safe to commit).
    """
    existing_set = set(existing_fingerprints)
    return [fp in existing_set for fp in new_fingerprints]
