o
    i?                     @   s
  d dl mZ ddlT d dlT d dlZd dlmZ d dlmZ d dl	m	Z	 d dl
mZmZmZmZmZ d dlT d d	lmZmZ d d
lmZ G dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZdS )    )serializers   )*N)JsonResponse)languageKey)datetime)validatePasswordgenerateTokengetSubscriptionInfovalidateParentIdgetMedicalProfile)FinancialProfileMedicalProfile)FinancialProfileSerializerc                   @   sH   e Zd Ze Ze Ze Ze ZejddZ	dd Z
dd ZdS ) ForgetOrChangePasswordSerializer )defaultc           
      C   s  d}d }d|v r|d }nd}d }d|v r"|d }t |dkr!d}nd}d }d|v r/|d }nd	}d }d }d
|v rM|d
 }|dkrLd|v rJ|d }nd}nd}||krUd}tjj|d}| dkry|d }	|dkrx|d urv|	j|krud}nd}nd}t|dkrtd|gi|S )Nr   phonePhone is requirednewPasswordT'Password must consists of 6 digits onlyzNew Password is requiredconfirmPasswordzConfirm Password is requiredflagchangeoldPasswordzOld Password is requiredzFlag is requiredzMismatch Passwordr   r   zInvalid old PasswordzOld Password is RequiredNo records found by phoneerror)	r   Parentobjectsfilter__len__passwordlenr   ValidationError)
selfdataerrorMessager   r   r   r   r   
parentListselected r*   ]/var/www/snowflake_co_dev_github/snow_flake_back_end_deploy/mama_care_api/user/serializers.pyvalidate   sT   



z)ForgetOrChangePasswordSerializer.validatec                 C   s|   d}|d }|d }t jj|d}| dkr*|d }|d ur'||_|  nd}nd}t|dkr:td|git	i S )	Nr   r   r   r   r   zNot Updatedr   r   )
r   r   r    r!   r"   saver#   r   r$   r   )r%   validated_datar'   r   r   r(   r)   r*   r*   r+   createM   s   
z'ForgetOrChangePasswordSerializer.createN)__name__
__module____qualname__r   	CharFieldr   r   r   r   r   r,   r/   r*   r*   r*   r+   r      s    7r   c                   @   s|   e Zd Ze Ze Ze Z	e Z
e Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Zdd Zdd ZdS )SignUpSerializerc                 C   s8   d}zt |d }W n   d}Y |rt |rdS dS )NTF)phonenumbersparseis_valid_number)r%   r   isParsedparsed_numberr*   r*   r+   validatePhonei   s   
zSignUpSerializer.validatePhonec                 C   s"   t jj|d }|dkrdS dS )Nr   r   FT)r   r   r    count)r%   r   r;   r*   r*   r+   checkPhoneIsNotExistsu   s   z&SignUpSerializer.checkPhoneIsNotExistsc                 C   sd   d}d|v r |d }|  |dkr| |dkr|S d}nd}nd}t|dkr0td|gid S )	Nr   r   TzPhone is already registeredzInvalid Phoner   r   r   )r:   r<   r#   r   r$   )r%   r&   r'   r   r*   r*   r+   
checkPhone{   s   zSignUpSerializer.checkPhonec                 C   s>   d}d}d|v r|d }nd}t |dkrtd|gi|S )Nr   FisTryingToBePregnantz$isTryingToBePregnant key is requiredr   r   )r#   r   r$   )r%   r&   r'   r>   r*   r*   r+   checkIsTryingToBePregnant   s   
z*SignUpSerializer.checkIsTryingToBePregnantc                 C   sJ   d|v r|d }t |dkr|S d}nd}t|dkr#td|gid S )Nr"   Tr   zPassword is requiredr   r   )r   r#   r   r$   )r%   r&   r"   r'   r*   r*   r+   checkPassword   s   zSignUpSerializer.checkPasswordc                 C   sB   d}t  }d|v r|d }nd}t|dkrtd|gi|S )Nr   dueDateOrBirthdayz!dueDateOrBirthday key is requiredr   r   )r   nowr#   r   r$   )r%   r&   r'   rA   r*   r*   r+   checkDueDateOrBirthday   s   
z'SignUpSerializer.checkDueDateOrBirthdayc                 C   sB   d }t jjdd}| dkr|d }|d u rtddgi|S )NidkkeyNamer   r   zGender is required)Genderr   r    r!   r   r$   )r%   r&   selectedGender
genderListr*   r*   r+   	getGender   s   zSignUpSerializer.getGenderc                 C   sb   d}d }t jj|d d}| dkr|d }|jdkrd}nd}t|dkr/td|gi|S )	Nr   
languageIdidr   FzLanguage is not enabledzlanguageId key is requiredr   )Languager   r    r!   	isEnabledr#   r   r$   )r%   r&   r'   selectedLanguagelanguageListr*   r*   r+   checkLanguage   s   
zSignUpSerializer.checkLanguagec                 C   sl  d }|  |}| |}| |}|dkr>| }t  }g }||kr-tjjdd}ntjjdd}|	 dkr>|d }| 
|}| |}	| |}
d}d}d}t|	|
|t t d}|  |jd urd}t||||dt t |d}|  |jd urd}t|t t d	}|  |jd urd}td
|	d|
d|d|t|jd|d|d|dt|ji	S )NFpregnantrE   childr   )r   r"   rK   createdDateupdatedDateT)r>   dateOfBirthchildTypeIdgenderId
isSelectedrU   rV   parentId)childIdrU   rV   r   r"   r>   rA   isParentCreatedisChildCreatedisMedicalProfileCreatedparent)rJ   rC   r?   dater   rB   	ChildTyper   r    r!   rR   r=   r@   r   r-   rM   Childr   r\   r   r   ParentSerializerr&   )r%   r.   rX   rH   rA   r>   todaychildTypeListlanguager   r"   r]   r^   r_   r`   rT   medicalProfiler*   r*   r+   r/      sz   










zSignUpSerializer.createN)r0   r1   r2   r   BooleanFieldr>   DateTimeFieldrA   r3   r   r"   IntegerFieldrK   r:   r<   r=   r?   r@   rC   rJ   rR   r/   r*   r*   r*   r+   r4   b   s    r4   c                   @   sZ   e Zd Ze Ze Ze Ze ZG dd dZ	dd Z
dd Zdd Zd	d
 ZdS )rd   c                   @   s   e Zd ZeZdgZdS )zParentSerializer.Metar"   N)r0   r1   r2   r   modelexcluder*   r*   r*   r+   Meta%  s    
rn   c                 C   s:   t jj|jd }|dkrt jj|jd}t|jS d S )Nr[   T)ParentDetailr   r    rM   existsgetParentDetailSerializerr&   )r%   instanceisExistsr)   r*   r*   r+   get_parentDetail)  s
   
z!ParentSerializer.get_parentDetailc                 C   s   t jj|jd}| dkrt|d jS tjjdd}| dkrUi }t|d j	|d< t
 |d< t
 |d< |d j|d< |j|d	< t|d
}| rU|  |jS d S )Nro   r   r`   rE   tokenrU   rV   tokenTypeIdr[   r&   )ParentTokenr   r    rM   r!   ParentTokenSerializerr&   	TokenTyper	   tokenTypeLenr   rB   is_validr-   )r%   rt   	tokenListselectedListparentTokenMapparentTokenSerializerr*   r*   r+   	get_token0  s    

zParentSerializer.get_tokenc                 C   
   t | |S N)r
   r%   rt   r*   r*   r+   get_subscriptionInfoD     
z%ParentSerializer.get_subscriptionInfoc                 C   sp   t jj|jd }|dkrt jj|jd}t|jS t	 t	 |jd}t|d}|
 r6|  |jS d S )Nro   T)rU   rV   r[   ry   )r   r   r    rM   rq   rr   r   r&   r   rB   r~   r-   )r%   rt   ru   r)   	finAccMapfinAccSerializerr*   r*   r+   get_financialAccountG  s   

z%ParentSerializer.get_financialAccountN)r0   r1   r2   r   SerializerMethodFieldparentDetailrw   subscriptionInfofinancialAccountrn   rv   r   r   r   r*   r*   r*   r+   rd     s    rd   c                   @   s"   e Zd ZG dd dZdd ZdS )rs   c                   @      e Zd ZeZg dZdS )zParentDetailSerializer.Meta)r[   	firstNamelastNameemailrU   rV   N)r0   r1   r2   rp   rl   fieldsr*   r*   r*   r+   rn   Z      rn   c                 C   R   d}d}d|v rt | |d j}nd}|dkr|S t|dkr'td|gid S Nr   Fr[   Parent Id does not exitTr   r   r   rM   r#   r   r$   r%   r&   r'   isCheckr*   r*   r+   r,   e     zParentDetailSerializer.validateN)r0   r1   r2   rn   r,   r*   r*   r*   r+   rs   Y  s    rs   c                   @   s   e Zd ZG dd dZdS )r{   c                   @   r   )zParentTokenSerializer.Meta)r[   rw   rU   rV   rx   N)r0   r1   r2   rz   rl   r   r*   r*   r*   r+   rn   w  r   rn   N)r0   r1   r2   rn   r*   r*   r*   r+   r{   v  s    r{   c                   @   s2   e Zd Ze ZG dd dZdd Zdd ZdS )EmergencyContactSerializerc                   @   r   )zEmergencyContactSerializer.Meta)rM   fullNamer   rU   rV   r[   isAuthorizedN)r0   r1   r2   EmergencyContactrl   r   r*   r*   r*   r+   rn     r   rn   c                 C      t | |jjS r   r   r[   rM   r   r*   r*   r+   get_isAuthorized     z+EmergencyContactSerializer.get_isAuthorizedc                 C   r   r   r   r   r*   r*   r+   r,     r   z#EmergencyContactSerializer.validateN)	r0   r1   r2   r   r   r   rn   r   r,   r*   r*   r*   r+   r   }  s
    r   c                   @   sb   e Zd Ze Ze Ze Ze ZG dd dZ	dd Z
dd Zdd Zd	d
 Zdd ZdS )ChildSerializerc                   @   r   )zChildSerializer.Meta)rM   r>   rZ   namerW   weightlengthheadrU   rV   rX   rY   r[   	childTypegenderrh   r   N)r0   r1   r2   rc   rl   r   r*   r*   r*   r+   rn     r   rn   c                 C   r   r   r   r   r*   r*   r+   r     r   z ChildSerializer.get_isAuthorizedc                 C   sN   d}d|v rt | |d j}nd}|dkr|S t|dkr%td|gid S )NFr[   r   Tr   r   r   )r%   r&   r   r'   r*   r*   r+   r,     s   zChildSerializer.validatec                 C   X   t | }|jd ur*tjj|jjd }|dkr*tjj|jjd}t|t	|idj
S d S NrL   T)context)getLanguagerX   rb   r   r    rM   rq   rr   ChildTypeSerializerr   r&   )r%   rt   rK   ru   selectedChildTyper*   r*   r+   get_childType     
zChildSerializer.get_childTypec                 C   r   r   )r   rY   rG   r   r    rM   rq   rr   GenderSerializerr   r&   )r%   rt   rK   ru   rH   r*   r*   r+   
get_gender  r   zChildSerializer.get_genderc                 C   r   r   )r   r   r*   r*   r+   get_medicalProfile  r   z"ChildSerializer.get_medicalProfileN)r0   r1   r2   r   r   r   r   rh   r   rn   r   r,   r   r   r   r*   r*   r*   r+   r     s    r   )rest_frameworkr   modelsdjango.db.modelsr5   django.httpr   mama_care_api.settingsr   r   common.commonr   r	   r
   r   r   basic.serializersuser_profile.modelsr   r   user_profile.serializersr   
Serializerr   r4   ModelSerializerrd   rs   r{   r   r   r*   r*   r*   r+   <module>   s&    S >:!