
    soj1)                         d dl mZmZ d dlmZ d dl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  G d d          Z G d de          Z G d d          Z G d de          ZdS )    )ABCabstractmethod)StrEnumN)phrases)	BaseModel)User)Emoji)
GameStatus)ReservedKeyboardKeys)UnauthorizedToViewItemException)Keyboardc            	       D    e Zd ZdZddedededefdZdefd	Zde	fd
Z
dS )EmojiLegendzClass for emoji legends.Nemojidescription	conditionstatusc                 >    || _         || _        || _        || _        dS )z
        Constructor

        :param emoji: The emoji
        :param description: The description
        :param condition: The condition
        :param status: The status
        N)r   r   r   r   )selfr   r   r   r   s         /app/src/model/enums/ListPage.py__init__zEmojiLegend.__init__   s%     "
 +'!    returnc                     | j         dz   S )N r   r   s    r   get_formattedzEmojiLegend.get_formatted!   s    zCr   c                 *    t          | j                  S )zG
        Get the game status

        :return: The game status
        )r
   r   r   s    r   get_game_statuszEmojiLegend.get_game_status$   s     $+&&&r   N)__name__
__module____qualname____doc__r	   stranyr   r   r
   r     r   r   r   r      s        """ "e "# "# "s " " " " s        ' ' ' ' ' ' 'r   r   c                       e Zd ZdZdZdZdS )ListFilterTypezEnum for list filter types.slN)r"   r#   r$   r%   STRINGLEGENDr(   r   r   r*   r*   .   s        %%FFFFr   r*   c            	       .    e Zd ZdZ	 ddedededefdZdS )	
ListFilterzClass for list filters.Nfilter_typer   r   legendc                 Z    || _         || _        || _        || _        d| _        d| _        dS )z
        Constructor

        :param filter_type: The filter type
        :param description: The description
        :param condition: The condition
        N)r1   r   r   r2   valuekey)r   r1   r   r   r2   s        r   r   zListFilter.__init__8   s4     ,7 +'#)
r   r!   )	r"   r#   r$   r%   r*   r&   r'   r   r   r(   r   r   r0   r0   5   s^        !! # #  	
      r   r0   c            	          e Zd ZdZej        Zej        Zd Zd Z	e
deddfd            Ze
efded	edee         fd
            Zd ZdefdZdefdZe
defd            Zdedz  fdZe
defd            ZdefdZdee         fdZdefdZdefdZdefdZdee         fdZededefd            ZdefdZ de!fdZ"dee#         fdZ$de!fdZ%de&fdZ'e(j)        fde*dedeee*                  fd Z+dS )!ListPagezAbstract class for list pages.c                     t                      | _        t                      | _        g | _        g | _        d| _        t          j        | _	        d| _
        d| _        d| _        d| _        i | _        dS )z
        Constructor
        NT)r   userr   objectemoji_legend_listfilter_list_activestring_filtercSTANDARD_LIST_SIZEdefault_limitr2   show_legend_listprevious_objectnext_objectlegend_filter_resultsr   s    r   r   zListPage.__init__U   sn    
 &&	!*4646)-1*.&*15-1 JL"""r   c                    |                                  | _        t          | j                  dk    rdS d |                                 D             D ]+}|g| _        |                                 | j        |j        <   ,g | _        dS )z0
        Init the legend filter results
        r   Nc                 8    g | ]}|j         t          j        u |S r(   )r1   r*   r.   ).0fs     r   
<listcomp>z7ListPage.init_legend_filter_results.<locals>.<listcomp>p   s.     
 
 
.BW1W1WA1W1W1Wr   )get_emoji_legend_listr;   lenget_filter_listr<   get_all_itemsrD   r2   )r   filter_items     r   init_legend_filter_resultsz#ListPage.init_legend_filter_resultsh   s     "&!;!;!=!=t%&&!++F
 
++--
 
 
 	R 	RK (3mD#=A=O=O=Q=QD&{'9::"$r   	object_idr   Nc                     dS )zk
        Set the object of the list

        :param object_id: The object id
        :return: None
        Nr(   )r   rP   s     r   
set_objectzListPage.set_objectw   	     	r   pagelimitc                     dS )z
        Get a list item for the log

        :param page: The page
        :param limit: The limit
        :return: The list item
        Nr(   )r   rT   rU   s      r   	get_itemszListPage.get_items   rS   r   c                 B    |                      dt          j                  S )zK
        Get all items for the log

        :return: The list item
           )rW   r7   	MAX_LIMITr   s    r   rM   zListPage.get_all_items   s     ~~a!3444r   c                 D    t          |                                           S )zS
        Get the total items count

        :return: The total items count
        )rK   rM   r   s    r   get_total_items_countzListPage.get_total_items_count   s     4%%''(((r   c                     | j                                         }g | _         t          |                                           }|| _         |S )zc
        Get the total items count without filters

        :return: The total items count
        )r<   copyrK   rM   )r   active_filterscounts      r   get_total_items_no_filter_countz(ListPage.get_total_items_no_filter_count   sF     05577"$D&&(())"0r   c                     dS )zQ
        Get the text for an item in the list

        :return: The text
        Nr(   r   s    r   get_item_textzListPage.get_item_text   s	     	r   c                     dS )zN
        Get the style for the current object's numbered list button.
        Nr(   r   s    r   get_item_button_stylezListPage.get_item_button_style   s	    
 tr   c                 N   | j         |                                 vrt                      t          |                                           }|                    | j                   }|dk    r||dz
           nd| _        |t          |          dz
  k     r||dz            nd| _        dS )zQ
        Get the details for the list item

        :return: The details
        r   rY   N )r:   rM   r   listindexrB   rK   rC   )r   	all_itemscurrent_item_indexs      r   get_item_detail_textzListPage.get_item_detail_text   s     ;d0022221333 ++--..	&__T[991Ca1G1GI(1,--T 	 2Dc)nnWXFX1X1XI(1,--^b 	 rr   c                 v    | j                                         D ]\  }}| j        |v r|c S t                      )I
        Get the emoji legend

        :return: The emoji legend
        )rD   itemsr:   r   )r   r2   resultss      r   get_emoji_legendzListPage.get_emoji_legend   sO      $9??AA 	 	OFG{g%% & .///r   c                     g }| j                                         D ]#\  }}| j        |v r|                    |           $t	          |          dk    rt                      |S )rn   r   )rD   ro   r:   appendrK   r   )r   legend_listr2   rp   s       r   get_emoji_legend_multiplez"ListPage.get_emoji_legend_multiple   sr     #9??AA 	+ 	+OFG{g%%""6***{q  1333r   c                 N    |                                                                  S )]
        Get the emoji legend formatted

        :return: The emoji legend formatted
        )rq   r   r   s    r   get_emoji_legend_formattedz#ListPage.get_emoji_legend_formatted   s"     $$&&44666r   c                 j    d                     d |                                 D                       dz   S )rw   rg   c                     g | ]	}|j         
S r(   r   )rG   r2   s     r   rI   z@ListPage.get_emoji_legend_multiple_formatted.<locals>.<listcomp>  s    TTTTTTr   r   )joinru   r   s    r   #get_emoji_legend_multiple_formattedz,ListPage.get_emoji_legend_multiple_formatted   s7     wwTT43Q3Q3S3STTTUUX[[[r   c           
          d}| j         D ]H}|t          j                            |j        |j        t          | j        |                             z  }It          j                            |          S )zG
        Get the legend text

        :return: The legend text
        rg   )	r;   r   LIST_EMOJI_LEGEND_ITEMformatr   r   rK   rD   LIST_EMOJI_LEGEND)r   legend_textemoji_legends      r   get_emoji_legend_list_textz#ListPage.get_emoji_legend_list_text  st      2 	 	L79@@"(D.|<==  KK (//<<<r   c                     g S )zS
        Get the emoji legend list

        :return: The emoji legend list
        r(   r   s    r   rJ   zListPage.get_emoji_legend_list  s	     	r   ri   c                 :    t           j        t          |           z   S )z$
        Get the filter key
        )r   FILTERr&   )ri   s    r   get_filter_keyzListPage.get_filter_key  s     $*SZZ77r   c                     t          |                                           D ]/\  }}|j        t          j        u r|                     |          c S 0dS )z+
        Get the string filter key
        N)	enumeraterL   r1   r*   r-   r   )r   ri   rN   s      r   get_string_filter_keyzListPage.get_string_filter_key&  sg    
 #,D,@,@,B,B"C"C 	2 	2E;&.*???**511111 @	2 	2r   c                 2    d}| j         D ]}||j        z  }|S )z6
        Get the active filter list condition
        T)r<   r   )r   r   list_filters      r    get_active_filter_list_conditionz)ListPage.get_active_filter_list_condition/  s0     	2 	/ 	/K..IIr   c           	          g }t          | j                  dk    rD| j        D ]<}|                    t          t          j        |j        |j        |                     =|S )zG
        Get the filter list

        :return: The filter list
        r   )r2   )rK   r;   rs   r0   r*   r.   r   r   )r   filter_listr2   s      r   rL   zListPage.get_filter_list9  s}     t%&&**0  ""&-*(%	      r   c                 d    |                                  }t          |          dk    r|d         S dS )z
        Get the direct item. If it returns not None, instead of showing a list of items,
        It will show the item detail directly
        rY   r   N)rM   rK   )r   rj   s     r   get_direct_itemzListPage.get_direct_itemP  s5     &&((	y>>QQ<tr   c                 .    |                                  duS )z3
        Check if the list has direct item
        N)r   r   s    r   has_direct_itemzListPage.has_direct_item]  s    
 ##%%T11r   inbound_keyboarditem_keyc                 (   g }| j         @|                    t          t          j        || j         j        i|j                             | j        @|                    t          t          j        || j        j        i|j                             |gS )z
        Get the previous and next object keyboard
        :param inbound_keyboard: The inbound keyboard
        :param item_key: Key to access the item
        return The keyboard for previous and next object
        N)infoinbound_info)	rB   rs   r   r	   
LEFT_ARROWidr   rC   RIGHT_ARROW)r   r   r   keyboard_lines       r   %get_previous_and_next_object_keyboardz.ListPage.get_previous_and_next_object_keyboardd  s     )+ +  $"D$8$;<!1!6     '  %"D$4$78!1!6     r   ),r"   r#   r$   r%   r>   r?   DEFAULT_LIMITrZ   r   rO   r   intrR   rh   r   rW   rM   r\   ra   r&   rc   re   rl   r   rq   ru   rx   r|   r   rJ   staticmethodr   r   r'   r   r0   rL   r   boolr   r   DEFAULT_PRIMARY_KEYr   r   r(   r   r   r7   r7   O   s       (((MIL L L&% % % C D    ^ 0=  c # $y/    ^5 5 5)s ) ) ) )     s    ^sTz     c    ^*0+ 0 0 0 04+<    "7C 7 7 7 7\S \ \ \ \=C = = = =$tK'8     8c 8c 8 8 8 \82s 2 2 2 2#    j!1    .    2 2 2 2 2 ;O:b    ( 47 	d8n	           r   r7   )abcr   r   enumr   	constantsr>   	resourcesr   src.model.BaseModelr   src.model.Userr   src.model.enums.Emojir	   src.model.enums.GameStatusr
   $src.model.enums.ReservedKeyboardKeysr   src.model.error.CustomExceptionr   src.model.pojo.Keyboardr   r   r*   r0   r7   r(   r   r   <module>r      s   # # # # # # # #                 ) ) ) ) ) )       ' ' ' ' ' ' 1 1 1 1 1 1 E E E E E E K K K K K K , , , , , ,' ' ' ' ' ' ' '>    W          4u u u u us u u u u ur   