
    ]i                         d Z ddlmZmZ ddlmZ ddlmZ ddlmZ dZ	dZ
dZd	Zd
ZdZdZdedededz  fdZ	 ddededededz  def
dZdedefdZdedefdZy)uR   System repository — all DB queries for system-wide configuration (SystemConfig).    )datetimetimezone)select)AsyncSession)SystemConfigmaintenance_modeenvironment_modenumber_thousand_separatornumber_decimal_separatornumber_decimal_placesnumber_negative_formatnumber_negative_colordbkeyreturnNc                    K   | j                  t        t              j                  t        j                  |k(               d{   }|j                         S 7 w)zAFetch a system config entry by key, or None if it does not exist.N)executer   r   wherer   scalar_one_or_none)r   r   results      D/var/www/html/spbu.com/backend/app/repositories/system_repository.py
get_configr      sG     ::f\2889I9IS9PQRRF$$&& Ss   AAAAvalueuser_idc                   K   t        | |       d{   }|Bt        |||t        j                  t        j
                              }| j                  |       n6||_        ||_        t        j                  t        j
                        |_	        | j                          d{    | j                  |       d{    |S 7 7 !7 
w)zAUpsert a system config entry (insert if new, update if existing).N)r   r   updated_by_id
updated_at)r   r   r   nowr   utcaddr   r   r   flushrefresh)r   r   r   r   configs        r   
set_configr$      s      b#&&F~!||HLL1	
 	v&$LL6
((*
**V
M ' s4   C
CBC
$C%C
=C>C
C
C
c                 h   K   t        | t               d{   }|duxr |j                  dk(  S 7 w)z;Return True if the system is currently in maintenance mode.Ntrue)r   MAINTENANCE_KEYr   r   r#   s     r   is_maintenance_moder)   /   s3     b/22F8&,,&"88 3   202c                 h   K   t        | t               d{   }|duxr |j                  dk(  S 7 w)z1Return True if environment_mode is 'development'.Ndevelopment)r   ENV_MODE_KEYr   r(   s     r   is_dev_moder.   5   s3     b,//F?&,,-"?? 0r*   )N)__doc__r   r   
sqlalchemyr   sqlalchemy.ext.asyncior   app.models.systemr   r'   r-   NUMBER_THOUSAND_SEP_KEYNUMBER_DECIMAL_SEP_KEYNUMBER_DECIMAL_PLACES_KEYNUMBER_NEGATIVE_FORMAT_KEYNUMBER_NEGATIVE_COLOR_KEYstrr   intr$   boolr)   r.        r   <module>r=      s    X '  / *$!5 3 3 5 3 ' 'C 'L44G ' CG'*584Z,9, 94 9@, @4 @r<   