Ë
    ¼vëjÖ  ã                  ó„   — d Z ddlmZ ddlZddlZddlmZ ddlmZ  ej                  d«      Z	dZ
dd„Zdd	„Zdd
„Zdd„Zy)aæ  Owner notices in the platform bell: the Notifications table in the master DB, one row per active owner.

The AI credit pool and the storage allowances are the organisation's, shared by every product, so the product
whose call happens to cross a mark is the one that settles it. Rather than each product carrying its own
notifier, the library writes the notice itself, named GalaxiQ, not a product. A product may still pass its own
`tell_owners` to Credits; this is what runs otherwise.
é    )ÚannotationsN)Údatetime)ÚListzgalaxiq.ai_creditsÚOTHERc                óz   — |rd|j                   › d|d›�nd}| dk\  rdd|d›d	|› d
�fS d| › d�d|d›d|d›d|› d�fS )zA(title, description) for an AI credit mark, in the owner's words.zon ú z%bzwith your next billing periodéd   zGalaxiQ: AI credits used upzYou have used all ú,zY AI credits for this period. AI work across your GalaxiQ products waits until they renew z,, or sooner with a larger plan or an add-on.z	GalaxiQ: z% of your AI credits usedzYou have used z of z( AI credits for this period. They renew ú.)Úday)ÚmarkÚusedÚlimitÚ	renews_atÚwhens        úa/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/galaxiq_utils/ai_credits/notices.pyÚowner_noticer      sŒ   € á3<ˆS�—‘�˜q ¨2 Ñ/ÐBa€DØˆs‚{Ø-Ø$ U¨1 Ið .*Ø*.¨Ð/[ð]ð^ð 	^ð ˜�vÐ6Ð7Ø˜T !˜H D¨¨q¨	Ð1YÐZ^ÐY_Ð_`Ðaðcð có    c                ó¸   — | j                  dt        |«      j                  d«      df«      j                  «       }|D �cg c]  }t        |d   «      ‘Œ c}S c c}w )zÎUser ids of every active member of the organisation, however the product spells the tenant. Everyone in
    the organisation hears about its AI credits and storage, not only the owners (decided 2026-10-31).z´SELECT m."userId" FROM "Organisations" o JOIN "OrganisationMembers" m ON m."organisationId" = o.id WHERE o."tenantId"::text = %s AND m."userId" IS NOT NULL AND upper(m.status) = %sÚorg_ÚACTIVEr   )ÚexecuteÚstrÚremoveprefixÚfetchall)ÚconnÚ	tenant_idÚrowsÚrs       r   Úfind_membersr       s\   € ð �<‰<ð	\ô 
ˆY‹×	$Ñ	$ VÓ	,¨hÐ7ó	9÷ :B¹»ð	 	ð
  $Ö$˜!ŒC��!‘�IÒ$Ð$ùÒ$s   ¿Ac           	     óü   — t        | |«      }|D ]8  }| j                  dt        t        j                  «       «      |||t
        f«       Œ: | j                  «        |st        j                  d||«       t        |«      S )z_Writes one bell notice for every active member of the organisation; returns how many were told.zˆINSERT INTO "Notifications" (id, "userId", title, description, type, "createdAt", "updatedAt") VALUES (%s, %s, %s, %s, %s, now(), now())z1notices: %s has no active member to tell about %r)
r    r   r   ÚuuidÚuuid4ÚNOTIFICATION_TYPEÚcommitÚlogÚinfoÚlen)r   r   ÚtitleÚdescriptionÚmembersÚuser_ids         r   Útell_membersr-   *   su   € ä˜4 Ó+€GØò QˆØ�‰ð8ä”—‘“Ó ¨°Ô=NÐOõ	QðQð
 	‡K�K„MÙÜ�‰ÐDÀiÐQVÔWÜˆw‹<Ðr   c                ó@   — t        ||||«      \  }}t        | |||«      S )z0The AI credit notice at a mark, for every owner.)r   r-   )r   r   r   r   r   r   r)   r*   s           r   Útell_members_in_the_bellr/   8   s(   € ä% d¨D°%¸ÓCÑ€Eˆ;Ü˜˜i¨°Ó<Ð<r   )
r   Úintr   r0   r   r0   r   r   ÚreturnÚtuple)r   r   r1   z	List[str])r   r   r)   r   r*   r   r1   r0   )r   r   r   r0   r   r0   r   r0   r   r   r1   r0   )Ú__doc__Ú
__future__r   Úloggingr"   r   Útypingr   Ú	getLoggerr&   r$   r   r    r-   r/   © r   r   ú<module>r9      sI   ðñõ #ã Û Ý Ý à€g×ÑÐ,Ó-€àÐ ócó%óô=r   