Ë
    esjk  ã                   óÊ   — d Z ddlZddlZddlmZmZ  ej                  e«      ZdZ	de
de
fd„Zdd	d
ddœZ ee«      Zde
defd„Zde
dedefd„Zde
de
de
de
fd„Zde
defd„Zy)a”  Per-tenant email settings: whether the bot may email, and the copy it uses.

Stored as JSON in the tenant's existing strategist_summaries table under
ingestion_type 'email_settings', the same mechanism brand_persona and location
already use. No new table.

The header/footer/disclaimer strings are tenant-authored and may contain
{{brandName}} and {{currentYear}} placeholders, matching the settings UI.
é    N)Úget_latest_summaryÚinsert_summaryÚemail_settingsÚ	tenant_idÚreturnc                 ó^   — | xs dj                  «       } | r| j                  d«      sd| › �S | S )zýAccept a tenant id with or without the org_ prefix.

    Schemas are named org_<uuid>. Callers sometimes pass the bare uuid, and
    without this a bootstrap would silently create a second, empty schema whose
    settings the chat would never read.
    Ú Úorg_)ÚstripÚ
startswith)r   s    ú:/var/www/html/strategist-ai/app/services/email_settings.pyÚnormalise_tenant_idr      s9   € ð ’˜b×'Ñ'Ó)€IÙ˜×-Ñ-¨fÔ5Ø�i�[Ð!Ð!ØÐó    Tz&Thanks for chatting with {{brandName}}u6   Â© {{currentYear}} {{brandName}}. All rights reserved.zzResponses are powered by AI and may contain errors or omissions. Please verify important information before relying on it.)ÚenabledÚheaderÚfooterÚaiDisclaimerc                 ó  — t        | «      } t        t        «      }	 t        | t        «      \  }}|s|S 	 t        j                  |«      }t        |t        «      r<|j                  |j                  «       D ��ci c]  \  }}|t        v sŒ||“Œ c}}«       |S # t
        $ r'}t        j                  d| › d|› �«       |cY d}~S d}~ww xY w# t        j                  t        f$ r t        j                  d| › d�«       |cY S w xY wc c}}w )z9Tenant's settings merged over the defaults. Never raises.z"Could not read email settings for z: NzStored email settings for z$ are not valid JSON; using defaults.)r   ÚdictÚDEFAULTSr   ÚSETTINGS_KEYÚ	ExceptionÚloggerÚerrorÚjsonÚloadsÚJSONDecodeErrorÚ	TypeErrorÚ
isinstanceÚupdateÚitemsÚALLOWED_KEYS)r   ÚsettingsÚstoredÚ_ÚexÚsavedÚkÚvs           r   Úget_email_settingsr*   /   sñ   € ä# IÓ.€IÜ”H‹~€HðÜ& y´,Ó?‰	ˆ�ñ
 ØˆðÜ—
‘
˜6Ó"ˆô
 �%œÔØ�‰¨%¯+©+«-×M¡$ ! Q¸1ÄÒ;L˜˜A™ÓMÔNØ€Oøô ò Ü�‰Ð9¸)¸ÀBÀrÀdÐKÔLØ�ûðûô × Ñ ¤)Ð,ò Ü�‰Ð1°)°Ð<`ÐaÔbØŠðüó
 Ns:   œB ´C
 Á7D
ÂD
Â	CÂ CÂ<CÃCÃ
4DÄ DÚupdatesc                 óÊ  — t        | «      } t        |«      t        z
  }|r&t        ddj	                  t        |«      «      › �«      ‚t        | «      }|j                  «       D ]=  \  }}|dk(  rt        |«      ||<   Œ|xs dj                  «       }|xs	 t        |   ||<   Œ? t        | t        t        j                  |«      «       t        j!                  d| › d|d   › �«       |S )zIMerge updates into the tenant's settings and persist. Returns the result.zUnknown setting(s): z, r   r	   zSaved email settings for z
: enabled=)r   Úsetr"   Ú
ValueErrorÚjoinÚsortedr*   r!   Úboolr   r   r   r   r   Údumpsr   Úinfo)r   r+   ÚunknownÚmergedÚkeyÚvalueÚtexts          r   Úsave_email_settingsr9   F   sØ   € ä# IÓ.€IÜ�'‹lœ\Ñ)€GÙÜÐ/°·	±	¼&À»/Ó0JÐ/KÐLÓMÐMä 	Ó*€FØ—m‘m“oò 0‰
ˆˆUØ�)ÒÜ˜u›+ˆF�3ŠKð ’K˜R×&Ñ&Ó(ˆDØÒ/¤(¨3¡-ˆF�3ŠKð0ô �9œl¬D¯J©J°vÓ,>Ô?Ü
‡K�KÐ+¨I¨;°jÀÈ	ÑARÐ@SÐTÔUØ€Mr   r8   Ú
brand_nameÚcurrent_yearc                 óN   — | xs dj                  d|«      j                  d|«      S )zMFill the {{brandName}} / {{currentYear}} placeholders the settings UI offers.r	   z{{brandName}}z{{currentYear}})Úreplace)r8   r:   r;   s      r   Úrender_placeholdersr>   [   s+   € àŠJ�B×Ñ °Ó<×DÑDØ˜<ó)ð )r   c                 ór   — t        «       }t        | «      j                  dd«      s|j                  d«       |S )aS  Tool names this tenant has switched off.

    Central place for per-tenant tool availability. As more optional tools
    arrive (meeting invites, voice), add their setting here and mark their
    prompt section with <<<TOOL:name>>> -- the chat loop and the prompt both
    read from this one function, so nothing else needs to change.
    r   TÚ
send_email)r-   r*   ÚgetÚadd)r   Údisableds     r   Údisabled_tools_forrD   a   s1   € ô ‹u€HÜ˜iÓ(×,Ñ,¨Y¸Ô=Ø�‰�\Ô"Ø€Or   )Ú__doc__r   ÚloggingÚapp.services.databaser   r   Ú	getLoggerÚ__name__r   r   Ústrr   r   r-   r"   r   r*   r9   r>   rD   © r   r   ú<module>rL      sÃ   ðñó Û ç Dà	ˆ×	Ñ	˜8Ó	$€à€ð
 3ð 
¨3ó 
ð Ø6ØFð	Dñ€ñ �8‹}€ð #ð ¨$ó ð. 3ð °ð ¸$ó ð*)˜cð )¨sð )À#ð )È#ó )ð #ð ¨#ô r   