Ë
    §‘ˆj°  ã                   ó‚   — d Z ddlZddlmZ ddlmZ ddlmZ  ej                  e	«      Z
dZdedefd	„Zdd
ededefd„Zy)ah  Runs the whole catalogue pipeline as one job.

A merchant presses one button. Making the frontend call three endpoints, poll
three jobs, and decide what to do when the second fails puts backend
orchestration in the UI -- so the sequence lives here and reports as a single
0-100.

The three stages stay individually callable for anyone who wants finer control.
é    N)Úget_sources)Úenrich_tenant)Úpair_tenant))Úsyncr   é
   )Úenrichr   é<   )Úpairr	   éd   ÚstartÚendc                 ó>   ‡ ‡‡— ‰ €ydt         dt        ddfˆˆ ˆfd„}|S )z;Maps a stage's own 0-100 into its slice of the overall bar.NÚpercentÚstepÚreturnc                 óB   •—  ‰‰‰‰z
  t        | «      z  dz  z   |«       y )Nr   )Úint)r   r   r   Úprogressr   s     €€€ú9/var/www/html/strategist-ai/app/services/catalog/build.pyÚreportz_scaled.<locals>.report   s$   ø€ Ù�˜# ™+¬¨W«Ñ5¸Ñ<Ñ<¸dÕCó    )r   Ústr)r   r   r   r   s   ``` r   Ú_scaledr      s1   ú€ àÐØðDœð D¤3ð D¨4÷ Dð €Mr   Ú	tenant_idÚforcer   c           
      óh  — di i}t        | «      }|rKddlm} |r |ddt        |«      › d�«         |||¬«      | t	        |gt
        d   dd ¢­Ž ¬	«      |d   d
<   n+t        j                  d| «       ddi|d   d
<   |r	 |dd«       t        | |t	        |gt
        d   dd ¢­Ž ¬«      |d   d<   t        | t	        |gt
        d   dd ¢­Ž ¬	«      |d   d<   |r	 |dd«       |d   d   }|j                  dd«      |d<   |j                  dd«      |d<   t        j                  d| |d   |d   «       |S )aL  Sync, enrich and pair, in that order, as one unit of work.

    Ordering is not a preference: pairing reads the attributes enrichment
    writes. is_accessory is what makes a phone suggest a case and stops a case
    suggesting a phone, so pairing an un-enriched catalogue produces a graph
    with no complements worth having.
    Ústagesr   )Ú_sync_sourceszsyncing z
 source(s))r   é   N)r   r   z*No connected sources for %s; skipping syncÚskippedzno connected sourcesr   zno sources to sync)r   r   r   é   r
   r   zcatalogue readyÚproductsÚpairsz-Built catalogue for %s: %s products, %s pairs)r   Úapp.api.endpointsr   Úlenr   ÚSTAGESÚloggerÚinfor   r   Úget)r   r   r   r   Úsourcesr   r#   s          r   Úbuild_catalogr+   #   sp  € ð ˜ˆ^€Fä˜)Ó$€GÙõ 	4áÙ�Q˜(¤3 w£< .°
Ð;Ô<Ø#F¡=°ÀÔ#FØ¤¨Ð A´6¸!±9¸Q¸R°=Ò Aô$CˆˆxÑ˜Ò ô
 	�‰Ð@À)ÔLØ$-Ð/EÐ#FˆˆxÑ˜Ñ ÙÙ�RÐ-Ô.ä!.Ø˜¬°Ð)J¼FÀ1¹IÀaÀb¸MÒ)Jô"L€Fˆ8Ñ�XÑô  +ØœG HÐ=¬v°a©y¸¸¨}Ò=ô ?€Fˆ8Ñ�VÑñ Ù�Ð'Ô(à�8Ñ˜VÑ$€EØŸ™ :¨qÓ1€Fˆ:ÑØ—i‘i ¨Ó+€Fˆ7�OÜ
‡K�KÐ?Ø˜6 *Ñ-¨v°g©ô@à€Mr   )NF)Ú__doc__ÚloggingÚapp.services.catalog.sourcesr   Úapp.services.enrichment.jobr   Úapp.services.pairing.jobr   Ú	getLoggerÚ__name__r'   r&   r   r   r   ÚboolÚdictr+   © r   r   ú<module>r6      s_   ðñó å 4Ý 5Ý 0à	ˆ×	Ñ	˜8Ó	$€ð
 
B€ð˜Sð  só ñ*˜Sð *¸ð *Èô *r   