
    ējt                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 e G d d             Z
e G d	 d
             Z	 	 	 	 	 	 	 	 ddZy)a  
Canonical data contracts for the PDF import pipeline.

StagedTransaction and ParseError are the only types parsers ever return.
Parsers NEVER import from ORM models, Flask, or SQLAlchemy.

compute_dedup_hash() is the canonical hash function used by:
  - All PDF parsers (when building StagedTransaction instances)
  - The transactions blueprint (Story 3.3, manual entry dedup)
  - staging_pipeline.py (Story 9.1, pre-commit dedup check)
    )annotationsN)	dataclass)date)Decimalc                  l    e Zd ZU dZded<   ded<   ded<   ded<   ded	<   ded
<   ded<   ded<   ded<   y)StagedTransactionzCCanonical output of any PDF/CSV parser. Never touches the database.r   strmerchant_rawmerchant_normalizedr   amountbool	is_creditissuer
dedup_hashfloatconfidence_scoreraw_textN__name__
__module____qualname____doc____annotations__     9/var/www/html/financials/app/services/pdf_parsers/base.pyr   r      s5    M
JOOKOMr   r   c                  :    e Zd ZU dZded<   ded<   ded<   ded<   y)	
ParseErroruG   Structured parse failure — surfaced per-row, not raised as exception.intpage_numberr	   r   reasonparser_versionNr   r   r   r   r   r   "   s    QMKr   r   c                    |  t        |       |j                          }t        j                  |j	                  d            j                         S )a=  
    Canonical dedup hash: SHA256(normalized_merchant + str(amount) + date.isoformat()).

    Args:
        normalized_merchant: Cleaned merchant name (post-normalization).
        amount: Transaction amount as Decimal.
        txn_date: Transaction date.

    Returns:
        64-character lowercase hex digest.
    zutf-8)r	   	isoformathashlibsha256encode	hexdigest)normalized_merchantr   txn_datepayloads       r   compute_dedup_hashr,   +   sF      %%c&k]83E3E3G2HIG>>'..12<<>>r   )r)   r	   r   r   r*   r   returnr	   )r   
__future__r   r%   dataclassesr   datetimer   decimalr   r   r   r,   r   r   r   <module>r2      sv   
 #  !   
 
 
   ??? ? 		?r   