
    iC                        d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
mZmZ ddlmZmZmZ ddZe
j$                  Zej$                  Zej$                  ZddZdd	Zdd
ZddZddZ	 d	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZddZddZg dZy)u  
Facade over :mod:`storage.db_repo`.

* **Published** (`insert_user_profiling_row`) — API / forced runs; admins read `dbo.user_profiling`.
* **Staging** (`insert_user_profiling_staging_row`) — scheduled batch only; use
  :meth:`ProfilingRepository.publish_staging_to_published` after a full scan.

``db`` may be a SQLAlchemy :class:`~sqlalchemy.engine.Engine` to bind the repository
to that engine (e.g. tests). Other values use the env-driven singleton.
    )annotations)AnyDictOptional)Engine)UserProfilingUserProfilingStagingUserProfilingTracker)ProfilingRepositoryget_profiling_repositoryprofile_data_to_jsonc                L    t        | t              rt        |       S t               S N)
isinstancer   r   dbs    E/var/www/html/userprofiledev.eatanceapp.com/storage/user_profiling.py_profiling_repor      s     "f'++#%%    c                6    t        |       j                          y r   r   ensure_tablesr   s    r   ensure_user_profiling_tabler           B%%'r   c                6    t        |       j                          y r   r   r   s    r   #ensure_user_profiling_tracker_tabler   $   r   r   c                6    t        |       j                          y r   r   r   s    r   ensure_profiling_storage_tablesr   (   r   r   c                8    t        |       j                  ||      S r   )r   should_skip_scheduled_run)r   user_idrecency_dayss      r   !tracker_should_skip_scheduled_runr#   ,   s    288,OOr   c                8    t        |       j                  |       y r   )r   touch_tracker)r   r!   s     r   upsert_user_profiling_trackerr&   0   s    B%%g.r   Nc                <    t        |       j                  |||       y)zAUpsert **published** dbo.user_profiling + tracker (API / forced).N)r   upsert_publishedr   r!   profile_datadeep_analysis_markdowns       r   insert_user_profiling_rowr,   4   s     B((,@VWr   c                <    t        |       j                  |||       y)zIUpsert **staging** only (batch job). Does not touch tracker or published.N)r   upsert_stagingr)   s       r   !insert_user_profiling_staging_rowr/   >   s     B&&w>TUr   c                6    t        |       j                          y)uQ   Promote staging → published in one DB transaction (call after full batch scan).N)r   publish_staging_to_publishedr   s    r   publish_profiling_stagingr2   H   s    B446r   c                6    t        |       j                          y)z9Clear staging at the start of a new batch from user id 0.N)r   truncate_stagingr   s    r   truncate_profiling_stagingr5   M   s    B((*r   )USER_PROFILING_TABLEUSER_PROFILING_STAGING_TABLEUSER_PROFILING_TRACKER_TABLEr   r   r   r,   r/   r   r2   r#   r5   r&   )returnr   )r9   None)r!   intr"   r;   r9   bool)r!   r;   r9   r:   r   )r!   r;   r*   zDict[str, Any]r+   zOptional[str]r9   r:   ) __doc__
__future__r   typingr   r   r   sqlalchemy.enginer   storage.db_modelr   r	   r
   storage.db_repor   r   r   r   __tablename__r6   r7   r8   r   r   r   r#   r&   r,   r/   r2   r5   __all__ r   r   <module>rF      s   	 # & & $ V V _ _&
 %22 3AA 3AA (((P/ -1	XX !X *	X
 
X -1	VV !V *	V
 
V7
+
r   