
    soj                         d dl m Z 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
ej        ddfdZdd dd ej        dfde	de	dedededededededededefdZdS )    )datetime	timedelta)ContextTypes)
BountyLoan)	GroupChat)User)BountyLoanSource)BountyLoanStatus)BountyLoanExpiredNotification)send_notificationcontextreturnNc                 p  K   t          j                                        t           j        t          j        k    t           j        t          j                    k     z            }|D ]P}t          j	        |_        |
                                 t          | |j        t          |                     d{V  QdS )zT
    Set expired bounty loans
    :param context: The context
    :return: None
    N)r   selectwherestatusr
   ACTIVEdeadline_dater   nowEXPIREDsaver   borrowerr   )r   expired_bounty_loansexpired_bounty_loans      '/app/src/service/bounty_loan_service.pyset_expired_bounty_loansr      s       .8->-@-@-F-F		.5	5#hlnn4	6. .
  4 

 

%5%="  """  ()*=>>
 
 	
 	
 	
 	
 	
 	
 	
 	


 

    loanerr   amount
group_chatsource
message_idtax_percentagerepay_amountdurationr   external_idc                    |dk    rt           j        }	|t          j        ur|
t	          d          ||}t                      }| |_        ||_        ||_        ||_	        ||_
        ||_        t          j                    t          |          z   |_        |	|_        ||_        ||_        |j        |_        |
|_        |                                 |S )a  
    Create a bounty loan
    :param loaner: The loaner
    :param borrower: The borrower
    :param amount: The amount
    :param group_chat: The group chat
    :param source: The source
    :param message_id: The message id
    :param tax_percentage: The tax percentage
    :param repay_amount: The repay amount
    :param duration: The duration in seconds. If 0, will set status to EXPIRED
    :param status: The status
    :param external_id: The external id
    :return: The bounty loan
    r   Nz+External id is required for non-user source)seconds)r
   r   r	   USER
ValueErrorr   r   r   r   r#   r$   r%   r   r   r   r   r   r    r"   valuer!   r&   r   )r   r   r   r    r!   r"   r#   r$   r%   r   r&   loans               r   add_loanr-   '   s    8 1}}!)%***{/BFGGG!||DDKDMDK(D$DDM!)H*E*E*EEDDK DO DO,DK"DIIKKKKr   )r   r   src.tg_compat.extr   src.model.BountyLoanr   src.model.GroupChatr   src.model.Userr    src.model.enums.BountyLoanSourcer	    src.model.enums.BountyLoanStatusr
   src.model.enums.Notificationr    src.service.notification_servicer   DEFAULT_TYPEr   r   intfloatr-    r   r   <module>r:      s   ( ( ( ( ( ( ( ( * * * * * * + + + + + + ) ) ) ) ) )       = = = = = = = = = = = = F F F F F F > > > > > >
L,E 
$ 
 
 
 
> /64 444 4 	4
 4 4 4 4 4 4 4 4 4 4 4 4 4r   