
    Pkjj                    R    d dl mZ d dlmZ d dlmZ d dlmZ dZdddZ	ddddZ
dS )    )annotations)
Connection)record_audit_event)nowzUAT12-20260516231955 connr   tablestrid_colwhereparamstuplereturn	list[str]c           	     ~    fd|                      d d| d| |                                          D             S )Nc                :    g | ]}t          |                   S r   )r
   ).0rr   s     -src/jarvis_finance/services/budget_cleanup.py
<listcomp>z_ids.<locals>.<listcomp>   s#    sssqC&	NNsss    zSELECT z FROM z WHERE )executefetchall)r   r	   r   r   r   s     `  r   _idsr      sR    ssssDLL1^61^1^1^1^W\1^1^`f$g$g$p$p$r$rssssr   Tdry_runr   booldict[str, int | bool]c          
        t          | dddt           df          }t          | dddt           df          }t          | dddt           df          }d	}t           dt           ddt           dg}|r=|d
d                    d |D                       z   dz   z  }|                    |           |r=|dd                    d |D                       z   dz   z  }|                    |           t          | dd|t	          |                    }d}t           dt           ddt           dg}	|r=|dd                    d |D                       z   dz   z  }|	                    |           t          | dd|t	          |	                    }
|t          |          t          |          t          |          t          |          t          |
          dd}|r|S t                      }|D ]}|                     d||f           |D ]}|                     d|||f           |D ]}|                     d||f           |D ]}|                     d||f           |
D ]}|                     d||f           t          | ddd t          d! |	                                D             d"d#$          }| 
                                 t          |          |d%<   |rd&nd|d'<   |S )(Nbudget_accountsbudget_account_idzname LIKE ?%budget_categoriescategory_idbudget_tagstag_idzLdescription LIKE ? OR COALESCE(payee,'') LIKE ? OR COALESCE(notes,'') LIKE ?z OR account_id IN (,c              3     K   | ]}d V  dS ?Nr   r   _s     r   	<genexpr>z,cleanup_uat12_budget_data.<locals>.<genexpr>   s"      4N4NQS4N4N4N4N4N4Nr   )z OR category_id IN (c              3     K   | ]}d V  dS r)   r   r+   s     r   r-   z,cleanup_uat12_budget_data.<locals>.<genexpr>   s"      5P5Pac5P5P5P5P5P5Pr   budget_transactionsbudget_transaction_idzOdescription LIKE ? OR COALESCE(merchant,'') LIKE ? OR COALESCE(notes,'') LIKE ?z OR proposed_category_id IN (c              3     K   | ]}d V  dS r)   r   r+   s     r   r-   z,cleanup_uat12_budget_data.<locals>.<genexpr>   s"      @[@[@[@[@[@[@[@[r   budget_transaction_candidatestransaction_candidate_idr   )r   accounts
categoriestransactionstags
candidatesarchived_transactionsz\UPDATE budget_transactions SET status='archived', updated_at=? WHERE budget_transaction_id=?z]UPDATE budget_accounts SET is_active=0, archived_at=?, updated_at=? WHERE budget_account_id=?zJUPDATE budget_categories SET is_active=0, updated_at=? WHERE category_id=?z?UPDATE budget_tags SET is_active=0, updated_at=? WHERE tag_id=?zUPDATE budget_transaction_candidates SET status='ignored', notes=COALESCE(notes,'') || ' | UAT12 cleanup archived', updated_at=? WHERE transaction_candidate_id=?runtime_cleanupuat12_budget_cleanupbudget_runtime_cleanupc                &    i | ]\  }}|d k    ||S r   r   )r   kvs      r   
<dictcomp>z-cleanup_uat12_budget_data.<locals>.<dictcomp>6   s#    GGGTQYAqr   z>Archived UAT12 budget test data after verified runtime backup.user)sourceactionentity_type	entity_id
new_valuesuser_text_note
created_byr:      audit_events)r   UAT12_PREFIXjoinextendr   lenr   r   r   itemscommit)r   r   account_idscategory_idstag_idstx_where	tx_paramstransaction_ids
cand_wherecand_paramscandidate_idssummarytstxidaidcidtidcandaudit_ids                      r   cleanup_uat12_budget_datarc      s0   t.0C]XdUgUgUgTijjK1=-UaRdRdRdQfggL4-\BTBTBTAVWWG]H+...<0B0B0BDWDWDWDWXI &)CHH4N4N+4N4N4N,N,NNQTTT%%% '*SXX5P5P<5P5P5P-P-PPSVVV&&&4!68OQY[`aj[k[kllObJ!-000\2D2D2DFY,FYFYFYZK )5@[@[l@[@[@[8[8[[^aaa
<(((>@Z\fhmnyhzhz{{M!s;/?/?sS_O`O`ru  wF  sG  sG  QT  U\  Q]  Q]  mp  q~  m  m  Z[  \  \G 	B A Asvxz~u  	A  	A  	A  	A E Etwy{}  @C  wD  	E  	E  	E  	E n nadfhkclmmmm c cVY[]`Xabbbb F F  y  |~  @D  {E  	F  	F  	F  	F! %,GGW]]__GGGW	 	 	H 	KKMMM'*?';';G#$#+2aaGNNr   N)r   )r   r   r	   r
   r   r
   r   r
   r   r   r   r   )r   r   r   r   r   r   )
__future__r   sqlite3r   jarvis_finance.audit.logr   %jarvis_finance.services.budget_commonr   rL   r   rc   r   r   r   <module>rh      s    " " " " " "       7 7 7 7 7 7 5 5 5 5 5 5%t t t t t DH . . . . . . . .r   