
    soj+                         d dl T 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e          Ze                                 d	S )
    )*)	BaseModel)	GroupChat)User)BountyGiftRole)BountyGiftStatusc                   f   e Zd ZdZ eeddd          Z eeddd          Z e            Z	 e
            Z eej                  Z eeddd	d
          Z ed          Zedededefd            Zedededd fd            Zedededeeffd            ZdefdZ G d d          ZdS )
BountyGiftz
    BountyGift class
    bounty_gift_sendersCASCADE)backref	on_delete	on_updatebounty_gift_receivers)defaultTbounty_gift_groups_chatsRESTRICT)nullr   r   r   )r   userrolereturnc                 b   |t           j        u rt                                          t                              t          j                                                t          j        | k    t          j	        t          j        k    z                                            S t                                          t                              t          j                                                t          j        | k    t          j	        t          j        k    z                                            S )z
        Get the total amount of belly sent or received by a user
        param user: The user
        param role: The role (sender or receiver)
        return: The total amount of belly sent or received
        )r   SENDERr
   selectfnSUMamountwheresenderstatusr   	CONFIRMEDscalarreceiverr   r   s     /app/src/model/BountyGift.py get_total_belly_sent_or_receivedz+BountyGift.get_total_belly_sent_or_received!   s     >(((z01122&$.:3DHXHb3bc   LLVBFF:,--..U$,1BFVF`1`a  VXX	
    c                    |t           j        u rt                                                                          t          j        | k    t          j        t          j        k    z            	                    t          j
                                                                                  S t                                                                          t          j        | k    t          j        t          j        k    z            	                    t          j
                                                                                  S )z
        Get the highest bounty sent or received by a user
        param user: The user
        param role: The role (sender or receiver)
        return: The highest bounty sent or received
        )r   r   r
   r   r   r   r    r   r!   order_byr   descfirstr#   r$   s     r%   "get_highest_belly_sent_or_receivedz-BountyGift.get_highest_belly_sent_or_received=   s     >(((&$.:3DHXHb3bc  *+002233 LLVXXU$,1BFVF`1`a  Xj',,..//UWW	
r'   c                    |t           j        u r!t                                          t          j        t
                              t          j                                      d                    	                    t          j
        | k    t          j        t          j        k    z                                t          j                                      t
                              t          j                                                                                            }|j        |j        fS t                                          t          j
        t
                              t          j                                      d                    	                    t          j        | k    t          j        t          j        k    z                                t          j
                                      t
                              t          j                                                                                            }|j
        |j        fS )z
        Get the top user who was given the most belly or gave the most belly by/to a user and the total amount
        param user: The user
        param role: The role (sender or receiver)
        return: The top user and the total amount
        total)r   r   r
   r   r#   r   r   r   aliasr   r   r    r   r!   group_byr)   r*   r+   r.   )r   r   top_receiver
top_senders       r%   get_top_givers_or_receiverz%BountyGift.get_top_givers_or_receiver[   s    >(((
+RVVJ4E-F-F-L-LW-U-UVV&$.:3DHXHb3bc  *-.."&&!23388::;;   (,*<<< LLVJ%rvvj.?'@'@'F'Fw'O'OPPU$,1BFVF`1`a  Xj'((XbffZ.//446677UWW 	  *"222r'   c                 *    t          | j                  S )z<
        Get the status
        :return: The status
        )r   r    )selfs    r%   
get_statuszBountyGift.get_status}   s    
  ,,,r'   c                       e Zd ZdZdS )BountyGift.Metabounty_giftN)__name__
__module____qualname__db_table r'   r%   Metar8      s         r'   r?   N)r:   r;   r<   __doc__ForeignKeyFieldr   r   r#   BigIntegerFieldr   
FloatFieldtax_percentageSmallIntegerFieldr   AWAITING_CONFIRMATIONr    r   
group_chatIntegerField
message_idstaticmethodr   intr&   r,   r3   r6   r?   r>   r'   r%   r
   r
   
   s         _+yI  F -i  H _FZ\\N'7'MNNNF *  J 4(((J
t 
> 
c 
 
 
 \
6 
 
^ 
P\ 
 
 
 \
: 3 3^ 3s 3 3 3 \3B-, - - - -! ! ! ! ! ! ! ! ! !r'   r
   N)peeweesrc.model.BaseModelr   src.model.GroupChatr   src.model.Userr   src.model.enums.BountyGiftRoler    src.model.enums.BountyGiftStatusr   r
   create_tabler>   r'   r%   <module>rS      s        ) ) ) ) ) ) ) ) ) ) ) )       9 9 9 9 9 9 = = = = = ={! {! {! {! {! {! {! {!|        r'   