
    |iM                         S SK r S SKrS SKJr  S SK7  S SKJrJr  S SK7  S SKJr  S SK	r	S SK
r
S SKJr  S SKJr  S SKJrJr  S S	KJr  S
 rS rS rS rS rS rS rS rS rS rS rS rg)    N)serializers)*)SubscriptionOrderSubscriptionTransaction)datetime)Image)InMemoryUploadedFile)LanguagebasicPlanKeyName)SubscriptionPlanc                 H   U R                   R                  S5      (       Ga  U R                   S   R                  R                  SS 5      nU R                   S   R                  R                  SS 5      nU R                   S   R                  R                  SS 5      nSnUc  SnOUc  SnOUc  Sn[	        U5      S	:  a  [
        R                  " S
U/05      e[        R                  R                  US9R                  5       nUS:X  a  [        R                  R                  US9nUR                  R                  [        U5      :X  a  [        R                  R                  US9R                  5       nUS:X  ay  [        R                  R                  US9n	U	R                  R                  [        U5      :X  a6  U	R                  R                  [        U5      :X  a  U[        U5      :X  a  gSnOSnOSnOSnOSn[	        U5      S	:  a  [
        R                  " S
U/05      eg)NrequestparentIdchildIdmedicalProfileId zParent Id is requiredzChild Id is requiredzMedical Profile Id is requiredr   erroridTr   zInvalid Medical Profile Idz!Medical Profile Id does not existzInvalid Parent IdzChild Id does not exits)context__contains__query_paramsgetlenr   ValidationErrorChildobjectsfilterexistsr   r   intMedicalProfiler   )
selfselectedMedicalProfileIdr   r   r   errorMessageisExistChildselectedChildisExistMedicalProfileselectedMedicalProfiles
             `/Users/waleedhassanin/Documents/GitHub/snow_flake_back_end_deploy/mama_care_api/common/common.pyisValidDatar+      s   ||  ++<<	*77;;JM,,y)66::9dK<<	2??CC
 2L_1L%;L|q --w.GHH}}++w+7>>@4!MM---9M%%((CM9(6(>(>(E(E# )F )&( & )D0-;-C-C-G-GPW-G-X*-5588C= 088;;sCS?TT3s;K7LL#'+GL'C#FL24L|q --w.GHH    c                    U R                   R                  S5      (       a+  U R                   S   R                  R                  SS 5      nU$ U R                   R                  S5      (       a  U R                   S   nU$ S nU$ )Nr   isDashboard)r   r   headersr   )r#   r.   s     r*   getIsDashboardr0   B   sz    ||  ++ll9-5599-N
 	 
	"	"=	1	1ll=1  r,   c                 ~    U b:  [         R                  R                  U S9nUR                  (       a  UR                  $ g )Nr   )r
   r   r   	isEnabledr   )
languageIdselectedLanguages     r*   getLanguageRecordr5   K   s:    #++//:/>%%#&&&r,   c                 (   U R                   R                  S5      (       a.  U R                   S   R                  R                  [        S 5      nO:U R                   R                  [        5      (       a  U R                   [           nOS n[        U5      $ )Nr   )r   r   r/   r   languageKeyr5   )r#   r3   s     r*   getLanguager8   R   sk    ||  ++\\),4488dK
		"	";	/	/\\+.

Z((r,   c                 L    [        U 5      S:H  =(       a    U R                  5       $ )N   )r   isdigit)passwords    r*   validatePasswordr=   \   s    x=A4("2"2"44r,   c                 2    [         R                  " U 5      nU$ )N)secrets	token_hex)r   tokens     r*   generateTokenrB   _   s    c"ELr,   c                     U R                   R                  S5      (       a+  U R                   S   R                  R                  SS 5      nU$ g )Nr   r   )r   r   r   r   )r#   r   s     r*   getParentIdrD   c   sB    ||  ++<<	*77;;JM ,r,   c                     Sn[        U 5      nUb  Ub  U[        U5      :X  a  gSnOSnOSn[        U5      S:  a  [        R                  " SU/05      eg)Nr   TzParent Id is not matchedzParent Id is Requiredr   r   F)rD   r!   r   r   r   )r#   parentIdDatar%   parentIdRequests       r*   validateParentIdrH   h   sd    L!$'O"#s?3392L.
<1))7\N*CDDr,   c                    SnS nS nSn[         R                  R                  UR                  S9nUR	                  5       S:  a  US   n[
        R                  R                  US9R                  5       n[
        R                  R                  USS9nUR	                  5       S:  ag  US   n	[        R                  R                  U	R                  S9n
U
R	                  5       S:  a'  SnU	R                  R                  nU
S   R                  nUS:X  a  UUUS.$ [        R                  R                  [        S	9nUR	                  5       S:  a  US   R                  S
US.$ g )NFr   )r   )financialProfileId)rJ   	isExpired)subscriptionOrderIdT)keyNametransactionIdcount)rM   r   )FinancialProfiler   r   r   __len__r   rO   r   subscriptionPlanIdrM   rN   r   r   )r#   instanceisCheckrN   rM   soCount
finAccListfinAccsubscriptionOrderListselectedOrder	transListsubLists               r*   getSubscriptionInfor\   {   sz   %--44hkk4J
!#]F'//66#) 7 eg  %6$=$=$D$D#)U %E %! %,,.2 5a 83;;BB(5(8(8 C 	 $$&*"G+>>FFG$-aL$>$>Md?"!.   '..55>N5OG 1$&qz11%'$ 
 r,   c                    [         R                  R                  UR                  S9R	                  5       nUS:X  a<  [         R                  R                  UR                  S9n[        U5      R                  $ [        R                  " 5       [        R                  " 5       UR                  S.n[        US9nUR                  5       (       a  UR                  5         UR                  $ g )Nr   T)createdDateupdatedDater   )data)r"   r   r   r   r    r   MedicalProfileSerializerr`   r   nowis_validsave)r#   rS   isExistsselectedmedicalProfileMapmedicalProfileSerializers         r*   getMedicalProfileri      s    !))000ELLNt%--11(++1FH+H5:::  (||~'||~#;;!
 (@EV'W$'0022(--//444 3r,   c                 X   [         R                  " 5       n[        UR                  5      [        UR                  5      -   [        UR
                  5      -   [        UR                  5      -   [        UR                  5      -   [        UR                  5      -   n[        U 5      S-   U-   nU$ )N_)	r   rb   stryearmonthdayhourminutesecond)
weekNumberdtdtStringnames       r*   getImageNamerw      s    	BBGG
bhh-	
bff+	 bgg,	 bii.		
 bii.	  z?S 8+DKr,   c           
         U R                   S   R                  R                  S5      nU R                   S   R                  R                  S5      n[        R                  " UR                  S5      5      n[        R                  " U5      n[        R                  " U5      n[        R                  " 5       nUR                  XsR                  5       S9  [        USUS-   U-   UR                  5       S SUR                  5       -   S	9nU$ )
Nr   imageBase64imageExtensionzUTF-8)formatimage.zimage/)file
field_namerv   sizecharsetcontent_type)r   r`   r   base64	b64decodeencodeioBytesIOr   openrd   upperr	   tell)	r#   	imageNamery   rz   r`   bufimgimg_ionewImages	            r*   uploadImager      s    ,,y)..22=AK\\),11556FGNK..w78D
**T
C
**S/CZZ\FHHV002H3#_~-[[] 4 4 66H Or,   )r?   r   rest_frameworkr   mama_care_api.settingssubscription.modelsr   r   user_profile.serializersr   r   PILr   django.core.files.uploadedfiler	   basic.modelsr
   r   r   r+   r0   r5   r8   r=   rB   rD   rH   r\   ri   rw   r    r,   r*   <module>r      sj      & $ J &   	  ? 2 01f)5
&&P5 r,   