"""
GLAMWalk -- Volume 3: Data at Scale
09_walters_sentinel_bug_and_join_key.py

The real sentinel-value bug this project found (-99999 meaning 'date unknown,' not an ancient year) and the real filename convention used as Walters' join key.

Source: Volume Three, Sections 6.1-6.2
Targets Python 3.11.4 -- see Volume One, Chapter 1.5/1.6.
"""

def walters_qualifies(record):
    """
    -99999 is Walters' own database's sentinel value for 'date unknown' —
    NOT a real ancient year. A naive `year < 1930` check would let every
    one of these through by accident, since -99999 is, technically,
    less than 1930. Filter it out explicitly with a real-world floor.
    """
    year = record.get("date_begin_year")
    if year is None:
        return False
    year = int(year)
    if year < -3000:   # nothing in a real museum collection predates this;
                        # anything below it is a sentinel, not a real date
        return False
    return year < 1930


def extract_walters_object_number(filename):
    """
    Walters' own ObjectNumber sits between the first and second
    underscore in existing filenames — verified against every real
    filename shape encountered, including letter-prefixed accession
    numbers and multi-dot loan-number styles.
    """
    parts = filename.split("_")
    if len(parts) < 2:
        return None
    return parts[1]
