
    jh                     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 d dl	Z	d dl
mZ ej                  d        Z G d	 d
eeej                        Z G d deej                        Z G d deej                        Z G d deej                        Z G d deej                        Zy)    )db)login_manager)	UserMixin)generate_password_hashcheck_password_hash)datetimeN)SoftDeleteMixinc                 R    t         j                  j                  t        |             S N)Userquerygetint)user_ids     /var/www/html/app/auth/models.py	load_userr   	   s    ::>>#g,''    c                   X   e Zd ZdZ ej
                  ej                  d      Z ej
                   ej                  d      dd      Z	 ej
                   ej                  d      dd      Z
 ej
                   ej                  d            Z ej
                   ej                  d	            Z ej
                   ej                  d	            Z ej
                  ej                  ej                   
      Z ej
                  ej$                  d
      Z ej
                  ej$                  d
      Z ej
                   ej                  d            Z ej
                   ej                  d            Z ej
                   ej                  d      dd      Zd Zd Zd Zy)r   z5User model for authentication and profile informationTprimary_keyx   FuniquenullableP      2   defaultd   c                 "    d| j                    dS )Nz<User >)usernameselfs    r   __repr__zUser.__repr__    s    a((r   c                 $    t        |      | _        y r   )r   password_hashr%   passwords     r   set_passwordzUser.set_password#   s    3H=r   c                 .    t        | j                  |      S r   )r   r(   r)   s     r   check_passwordzUser.check_password&   s    "4#5#5x@@r   N)__name__
__module____qualname____doc__r   ColumnIntegeridStringemailr#   r(   
first_name	last_nameDateTimer   utcnow
created_atBoolean	is_activeis_admincompany	job_title
auth_tokenr&   r+   r-    r   r   r   r      sQ   ?	2::4	0BBIIibiinTEBEryy2teDHBIIibiin-M9299R=)J		)"))B-(I2;;@J		"**d3IryyU3H bii			#'G		)"))C.)I 9299S>$FJ)>Ar   r   c                       e Zd ZdZ ej
                  ej                  d      Z ej
                  ej                   ej                  d      d      Z	 ej
                   ej                  d      d      Z ej
                   ej                  d      d      Z ej
                  ej                  dej                  	      Z ej
                  ej                  d      Z ej
                  ej$                  d
      Z ej
                   ej                  d      d      Z ej*                  d ej,                  dd            Z fdZd Zd Z xZS )Subscriptionz.Subscription model for user subscription plansTr   user.idFr   r      r   r   r   r    r   r   subscription)uselistbackrefc                     t        t        | 
  |i | | j                  s#t	        t        j                               | _        y y r   )superrD   __init__subscription_idstruuiduuid4r%   argskwargs	__class__s      r   rP   zSubscription.__init__8   s8    lD*D;F;###&tzz|#4D  $r   c                 <    d| j                    d| j                   dS )Nz<Subscription z
 for User r"   )plan_idr   r$   s    r   r&   zSubscription.__repr__=   s    ~Z~QGGr   c                 f    | j                   dk(  xr! | j                  t        j                         kD  S )zCheck if subscription is activeactive)statusend_dater   r:   r$   s    r   r=   zSubscription.is_active@   s&    {{h&L4==8??;L+LLr   )r.   r/   r0   r1   r   r2   r3   r4   
ForeignKeyr   r5   rZ   r]   r9   r   r:   
start_dater^   r<   	is_annualrQ   relationshiprM   userrP   r&   r=   __classcell__rX   s   @r   rD   rD   *   s   8	2::4	0Bbii

MBMM)$<uMGbii			"6GRYYyryy}u5F2;;PJryyu5H		"**e4Ibii			#t<O 2??6:2::ne+TUD5
HMr   rD   c                   d    e Zd ZdZ ej
                  ej                  d      Z ej
                  ej                   ej                  d      d      Z	 ej
                  ej                   ej                  d      d      Z
 ej
                  ej                  d      Z ej
                   ej                  d      dd	
      Z ej
                  ej                  dej"                  
      Z ej
                   ej                  d            Z ej
                   ej                  d      d      Z ej
                   ej                  d      d      Z ej,                  d ej.                  dd            Z ej,                  d ej.                  dd            Z fdZd Z xZS )PaymentHistoryz8Payment history model for tracking subscription paymentsTr   rE   FrF   zsubscription.id   USDrH   r   r    rI   rG   r   paymentslazyrL   rD   c                     t        t        | 
  |i | | j                  s#t	        t        j                               | _        y y r   )rO   rg   rP   transaction_idrR   rS   rT   rU   s      r   rP   zPaymentHistory.__init__U   s8    nd,d=f="""%djjl"3D #r   c                 "    d| j                    dS )Nz<PaymentHistory r"   )rn   r$   s    r   r&   zPaymentHistory.__repr__Z   s    !$"5"5!6a88r   )r.   r/   r0   r1   r   r2   r3   r4   r_   r   rQ   Floatamountr5   currencyr9   r   r:   payment_datepayment_methodrn   r]   rb   rM   rc   rJ   rP   r&   rd   re   s   @r   rg   rg   E   sQ   B	2::4	0Bbii

MBMM)$<uMGbii

MBMM:K,LW\]ORYYrxx%0Fryy1uEH299R[[5(//RLRYYyryy}-NRYYyryy~d;NRYYyryy}u5F 2??6:2::jt+LMD"2??>:2::jW[;\]L4
9r   rg   c                      e Zd ZdZ ej
                  ej                  d      Z ej
                   ej                  d      dd      Z	 ej
                   ej                  d      d      Z
 ej
                  ej                        Z ej
                  ej                  d      Z ej
                  ej                  d      Z ej
                  ej                   di 	      Z ej
                  ej                   di 	      Z ej
                  ej&                  d
      Z ej
                  ej*                  ej.                  
      Z ej
                  ej*                  ej.                  ej.                        Zd Zy)SubscriptionPlanzASubscription plan model for defining available subscription plansTr   r   Fr   r    rF   rH   r   )r   onupdatec                 "    d| j                    dS )Nz<SubscriptionPlan r"   )namer$   s    r   r&   zSubscriptionPlan.__repr__l   s    #DII;a00r   N)r.   r/   r0   r1   r   r2   r3   r4   r5   rZ   ry   Textdescriptionrp   monthly_priceannual_priceJSONfeatureslimitationsr<   r=   r9   r   r:   r;   
updated_atr&   rB   r   r   rv   rv   ^   s   K	2::4	0Bbii			"dUCG299YRYYs^e4D"))BGG$KBIIbhh7M299RXX6Lryy5"=H"))BGGeR@K		"**d3I2;;@J2;;(//ZJ1r   rv   c                   b   e Zd ZdZ ej
                  ej                  d      Z ej
                  ej                   ej                  d      d      Z	 ej
                  ej                  ej                        Z ej
                  ej                        Z ej
                  ej                   ej                  d            Z ej
                   ej"                  d	      d
      Z ej
                  ej&                  d      Z ej*                  d ej,                  dd            Zd Zy)
QueryUsagezTQuery usage model for tracking SQL query execution for subscription plan enforcementTr   rE   FrF   r   zdatabase_connection.idrG   executer   query_usagerk   rL   c                 V    d| j                    d| j                   d| j                   dS )Nz<QueryUsage z - User z - r"   )r4   r   
query_typer$   s    r   r&   zQueryUsage.__repr__}   s+    dggYht||nC?PPQRRr   N)r.   r/   r0   r1   r   r2   r3   r4   r_   r   r9   r   r:   execution_timerz   
query_textconnection_idr5   r   r<   	is_cachedrb   rM   rc   r&   rB   r   r   r   r   p   s    ^	2::4	0Bbii

MBMM)$<uMGRYYr{{HOODN277#JBIIbjj-"--8P*QRM9299R=)<J		"**e4I 2??6:2::m$+OPDSr   r   )app.extensionsr   r   flask_loginr   werkzeug.securityr   r   r   rS   app.utils.soft_deleter	   user_loaderr   Modelr   rD   rg   rv   r   rB   r   r   <module>r      s     ( ! I   1( (A9orxx A:M?BHH M69_bhh 921 1$S"(( Sr   