
    soj              
       H   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dl m!Z!m"Z" d dl#m$Z$m%Z%m&Z&  G d de          Z' G d de          Z(dedej)        dededdf
dZ*dS )    )StrEnum)Update)ContextTypesN)	GroupUser)
Prediction)PredictionOptionUser)User)Emoji)ListPage)PredictionStatus)PredictionType)ReservedKeyboardKeys)Screen)Keyboard)get_items_text_keyboard)full_message_sendescape_valid_markdown_chars) get_user_prediction_status_emojiget_prediction_textget_user_prediction_status_textc                       e Zd ZdZdZdS )PredictionReservedKeysz+
    The reserved keys for this screen
    aN)__name__
__module____qualname____doc__ITEM_ID     2/app/src/chat/private/screens/screen_prediction.pyr   r      s          GGGr    r   c                   v     e Zd Z fdZdeddfdZej        fdee	         fdZ
d ZdefdZdef fd	Z xZS )
PredictionListPagec                 n    t                                                       t                      | _        dS )z
        Constructor
        N)super__init__r   objectself	__class__s    r!   r&   zPredictionListPage.__init__$   s*    
 	",,,r    	object_idreturnNc                 T    t          j        t           j        |k              | _        d S )N)r   getidr'   )r)   r+   s     r!   
set_objectzPredictionListPage.set_object-   s     nZ]i%?@@r    c                     |                                                      t          j                                        t          j                                                                      ||          S )a(  
        Get predictions that are open or closed/result set but user bet on them,
        or user created them,
        or they are of type user and are in sent status and
            (are public and creator is active in same group as user)
            or (user in same crew are creator)
        )get_select_items_statementorder_byr   datedesc	send_datepaginate)r)   pagelimits      r!   	get_itemszPredictionListPage.get_items0   sS     ++--Xjo**,,j.B.G.G.I.IJJXdE""	
r    c           
      >   | j                                                             t          j        t
          j        k    t          j        t          j	        k    z  t          j        
                    t
          j        t
          j        g          t          j        
                    t          j        t          j                                      t          j        | j        k                        z  z  t          j        | j        k    z  t          j        t          j	        k    t          j        t
          j        k    z  t          j        dk    t'          j        | j        t          j                  z  | j                            t          j                  z  z  z            S )NT)r'   selectwherer   statusr   SENTtyper   USERin_BETS_CLOSED
RESULT_SETr/   r   
predictionusercreator	is_publicr   *get_user_is_active_is_same_group_statement$get_in_same_crew_statement_condition)r)   s    r!   r2   z-PredictionListPage.get_select_items_statement>   sI   {!!##)) "&6&;;?n&99;
 !%%'7'CEUE`&abbM%%,34H4STTZZ05B  $ "9%. N$77$(8(==?
 $-5%P $	:+=  	FFzGYZZ/(*
 *
 *	
r    c                     | j         j        | j        k    rt          j        nd}|t          | j         | j                  z   }t          j                            |t          | j         j
                            S )N )r'   rG   rF   r
   rA   r   phrasesPREDICTION_ITEM_TEXTformatr   question)r)   user_is_creator_emojiemojis      r!   get_item_textz PredictionListPage.get_item_textk   si    .2k.ATY.N.N

TV%(HVZV_(`(``+22.t{/CDD
 
 	
r    c                     t                                                       t          j                            t          | j        d| j                  t          | j        | j        d                    S )NF)add_bets_commandrF   )rU   )	r%   get_item_detail_textrM   PREDICTION_ITEM_DETAIL_TEXTrO   r   r'   rF   r   r(   s    r!   rV   z'PredictionListPage.get_item_detail_textr   sa    $$&&&299e$)TTT+DKUZ[[[
 
 	
r    )r   r   r   r&   intr0   r   DEFAULT_LIMITlistr   r:   r2   strrS   rV   __classcell__)r*   s   @r!   r#   r#   #   s        / / / / /AC AD A A A A %-$: 
 
tJ?O 
 
 
 
+
 +
 +
Z
s 
 
 
 

c 
 
 
 
 
 
 
 
 
 
r    r#   updatecontextinbound_keyboardrF   r,   c                 `  K   t                      }||_        t          ||t          j        t
          j        t          j                  \  }}|}|	                    t          t          j        t
          j                  g           t          ||| ||t          j        g           d{V  dS )z
    Manage the prediction list screen
    :param update: The update
    :param context: The context
    :param inbound_keyboard: The inbound keyboard
    :param user: The user
    :return: None
    )text_fill_in)textscreen)r]   keyboardr_   excluded_keys_from_back_buttonN)r#   rF   r   r   r   r   PVT_PREDICTION_DETAILrM   PREDICTION_ITEM_TEXT_FILL_INappendr   
KEY_CREATEPVT_PREDICTION_CREATEr   r   PAGE)r]   r^   r_   rF   prediction_list_pageot_textitems_keyboardinline_keyboards           r!   managerp   {   s       0B/C/C $5&$9  G^ -;O 	w)&2N	O	O	OP    )(<(A'B           r    )+enumr   src.tg_compatr   src.tg_compat.extr   resources.phrasesrM   src.model.GroupUserr   src.model.Predictionr   src.model.PredictionOptionUserr   src.model.Userr	   src.model.enums.Emojir
   src.model.enums.ListPager    src.model.enums.PredictionStatusr   src.model.enums.PredictionTyper   $src.model.enums.ReservedKeyboardKeysr   src.model.enums.Screenr   src.model.pojo.Keyboardr   src.service.list_servicer   src.service.message_servicer   r   src.service.prediction_servicer   r   r   r   r#   DEFAULT_TYPErp   r   r    r!   <module>r      s                     * * * * * * # # # # # # ) ) ) ) ) ) + + + + + + ? ? ? ? ? ?       ' ' ' ' ' ' - - - - - - = = = = = = 9 9 9 9 9 9 E E E E E E ) ) ) ) ) ) , , , , , , < < < < < < V V V V V V V V             W   U
 U
 U
 U
 U
 U
 U
 U
p%%)6%JR%Z^%	% % % % % %r    