Ë
    ¼vëj·  ã                  óÔ   — d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	m
Z
mZ ddlmZmZ  ej                  d«      Ze G d	„ d
«      «       Ze G d„ d«      «       Zdd„Zdd„Zdd„Zdd„Zy)aí  The values a piece of content is made from, and whether a template fits them.

Values are gathered once per piece of content from the sources that know them (brand, journey, audience, behaviour,
identity, made). Copy values are written after the template is chosen, sized to its slots. Identity and behaviour
values may be left as tokens the sender fills per person. Missing is a fact: an optional value missing leaves its
element out; a required value missing means the template does not fit.é    )ÚannotationsN)Ú	dataclassÚfield)ÚAnyÚDictÚListÚOptionalé   )ÚTemplateÚValuez\{\{slot:([a-z_.]+)\}\}c                  ó|   — e Zd ZU  ee¬«      Zded<    ee¬«      Zded<    ee¬«      Zded<   dd„Z	dd	„Z
ddd„Zy
)ÚValues©Údefault_factoryúDict[str, Any]ÚheldzDict[str, Optional[str]]Ú
per_personzDict[str, bool]Úfiredc                ó4   — |d dg i fvr|| j                   |<   y y )NÚ )r   )ÚselfÚkeyÚvalues      ú_/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/galaxiq_utils/templates/values.pyÚputz
Values.put   s%   € Ø˜˜r 2 rÐ*Ñ*Ø"ˆD�I‰I�cŠNð +ó    c                ó>   — || j                   v xs || j                  v S ©N)r   r   )r   r   s     r   Úhasz
Values.has   s   € Ø�d—i‘iÐÒ9 3¨$¯/©/Ð#9Ð9r   Nc                ó:   — | j                   j                  ||«      S r   )r   Úget)r   r   Údefaults      r   r!   z
Values.get   s   € Ø�y‰y�}‰}˜S 'Ó*Ð*r   )r   Ústrr   r   ÚreturnÚNone)r   r#   r$   Úboolr   )r   r#   r"   r   r$   r   )Ú__name__Ú
__module__Ú__qualname__r   Údictr   Ú__annotations__r   r   r   r   r!   © r   r   r   r      s?   … á °Ô6€Dˆ.Ó6Ù+0ÀÔ+F€JÐ(ÓFÙ"°4Ô8€Eˆ?Ó8ó#ó:õ+r   r   c                  ód   — e Zd ZU ded<   ded<   ded<    ee¬«      Zded<   edd	„«       Zddd„Z	y
)ÚFitr   ÚtemplatezList[Value]ÚmissingÚleft_outr   ú	List[str]Útoo_longc                ó:   — | j                    xr | j                   S r   )r0   r3   )r   s    r   ÚokzFit.ok*   s   € à—<‘<ÐÒ5¨¯©Ð$5Ð5r   Nc                óô  — g }| j                   D ]Û  }|j                  dk(  rQ|j                  rE|xs i j                  |j                  «      sdnd}|j	                  d|j                  › d|› �«       Œc|j                  dk(  r|j	                  d«       Œ„|j
                  j                  d«      \  }}}|d	k(  rd
n|j                  dd«      }|j	                  d|dv r|n|dz   |z   › �«       ŒÝ | j                  D ]8  }|j	                  |j                  d«      d   j                  dd«      › d�«       Œ: |r+| j                  j                  › d�dj                  |«      z   S | j                  j                  › d�S )z1One plain sentence naming what would make it fit.Ú	behaviourznot firing yetz%firing, but not filled per person yetz
needs the z event, which is Úidentityzneeds people you know by nameú.ÚurlÚlinkÚ_ú zneeds )r   Úctaéÿÿÿÿz is longer than its spacez: z; z fits)r0   ÚsourceÚeventr!   Úappendr   Ú
rpartitionÚreplacer3   Úsplitr/   ÚnameÚjoin)	r   r   ÚpartsÚvÚstateÚfirstr<   ÚlastÚks	            r   Úwhy_notzFit.why_not.   sc  € àˆØ—‘ò 		^ˆAØ�x‰x˜;Ò&¨1¯7ª7Ø16²¸"×0AÑ0AÀ!Ç'Á'Ô0JÑ(ÐPw�Ø—‘˜z¨!¯'©'¨Ð2CÀEÀ7ÐKÕLØ—‘˜ZÒ'Ø—‘Ð<Õ=à!"§¡×!1Ñ!1°#Ó!6‘��q˜$Ø!%¨¢‘v°D·L±LÀÀcÓ4J�Ø—‘˜v¨e°{Ñ.B¡dÈÐPSÉÐVZÑHZÐ%[Ð\Õ]ð		^ð —‘ò 	[ˆAØ�L‰L˜AŸG™G C›L¨Ñ,×4Ñ4°S¸#Ó>Ð?Ð?XÐYÕZð	[á?D�$—-‘-×$Ñ$Ð% RÐ(¨4¯9©9°UÓ+;Ñ;ÐfÈTÏ]É]×M_ÑM_ÐL`Ð`eÐJfÐfr   )r$   r&   r   )r   zOptional[Dict[str, bool]]r$   r#   )
r'   r(   r)   r+   r   Úlistr3   Úpropertyr5   rN   r,   r   r   r.   r.   #   s;   … àÓØÓØÓÙ°Ô5€HˆiÓ5àò6ó ð6õgr   r.   c                óH  — g g }}| j                  «       D ]  }|j                  dk(  s|j                  |j                  «      rŒ.|j                  dk(  r$|j                  |j
                  |j                  <   Œa|j                  r|n|j                  |«       Œ� t        | ||«      S )a  Does this template fit these values? Copy is written after the pick, so it is never missing here. An identity
    value becomes a per-person token with its fallback. A behaviour value counts only when held for the whole
    audience or declared per person by the product.Úcopyr8   )	Úvaluesr@   r   r   Úfallbackr   ÚrequiredrB   r.   )r/   rS   r0   r1   rI   s        r   ÚfitrV   @   s�   € ð ˜BˆX€GØ�_‰_Óò 8ˆØ�8‰8�vÒ §¡¨A¯E©EÔ!2ØØ�8‰8�zÒ!Ø'(§z¡zˆF×Ñ˜aŸe™eÑ$ØØ—J’J‰ H×4Ñ4°QÕ7ð8ô ˆx˜ (Ó+Ð+r   c                óÚ  — g }| j                  «       D ]Õ  }|j                  dk7  s|j                  |vrŒ!||j                     }t        |t        «      rdj                  d„ |D «       «      n
t        |«      }|j                  r&t        |j                  «       «      |j                  kD  s&|j                  sŒ¢t        |«      |j                  kD  sŒ»|j                  |j                  «       Œ× |S )z4Copy keys whose text is longer than the slot allows.rR   r=   c              3  óœ   K  — | ]D  }t        |t        t        f«      rd j                  t	        t
        |«      «      n
t        |«      –— ŒF y­w)r=   N)Ú
isinstancerO   ÚtuplerG   Úmapr#   )Ú.0Úps     r   ú	<genexpr>zmeasure.<locals>.<genexpr>V   s9   è ø€ ÒhÐ^_´¸AÄÄe¸}Ô1M˜Ÿ™¤¤S¨!£Ô-ÔSVÐWXÓSYÓYÑhùs   ‚A
A)rS   r@   r   rY   rO   rG   r#   Ú	max_wordsÚlenrE   Ú	max_charsrB   )r/   rR   ÚoverrI   Útexts        r   Úmeasurerd   O   sÐ   € à€DØ�_‰_Óò ˆØ�8‰8�vÒ §¡¨dÑ!2ØØ�A—E‘E‰{ˆÜlvÐw{ô  ~Bô  mCˆs�x‰xÑhÐcgÔhÔhô  ILð  MQó  IRˆØ�KŠKœC §
¡
£Ó-°·±Ò;ÀÇÃÔQTÐUYÓQZÐ]^×]hÑ]hÓQhØ�K‰K˜Ÿ™Õðð €Kr   c                óP   — t        t        t        j                  | «      «      «      S )zUSlot tokens a renderer left behind. A render with any is a failed render, never sent.)ÚsortedÚsetÚTOKENÚfindall)Úrendereds    r   Úunfilledrk   \   s   € ä”#”e—m‘m HÓ-Ó.Ó/Ð/r   c                óL   — | j                  d«      d   }|r	d|› d|› d�S d|› d�S )zXThe token a sender fills per person, with the fallback written in: {{first_name|there}}.r9   r?   z{{ú|z}})rE   )r   rT   rF   s      r   Úperson_tokenrn   a   s9   € à�9‰9�S‹>˜"Ñ€DÙ+3ˆT�$��q˜˜
 $Ð'ÐJ¸4À¸vÀTÐ9JÐJr   )r/   r   rS   r   r$   r.   )r/   r   rR   r   r$   r2   )rj   r#   r$   r2   )r   r#   rT   zOptional[str]r$   r#   )Ú__doc__Ú
__future__r   ÚreÚdataclassesr   r   Útypingr   r   r   r	   Úspecr   r   Úcompilerh   r   r.   rV   rd   rk   rn   r,   r   r   ú<module>rv      sz   ðñJõ #ã 	ß (ß ,Ó ,ç !àˆ�
‰
Ð-Ó.€ð ÷+ð +ó ð+ð  ÷gð gó ðgó8,ó
ó0ô
Kr   