B
    CDb?!                 @   s   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mZ G dd deejZG d	d
 d
eejZG dd deejZG dd dejZdS )    )serializers)timezone)CountryFieldMixin)PriceStrategy)FeatureSerializer)get_price_with_currency_symbolget_country_currencyc               @   sj   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G dd dZdS )PriceStrategySerializerc             C   s   |j  }dd |D }|S )Nc             S   s   g | ]
}|j qS  )name).0fr
   r
   PG:\easytimepro\master/mysite/cloud\api\serializers\price_strategy_serializers.py
<listcomp>   s    z<PriceStrategySerializer.get_feature_name.<locals>.<listcomp>)featureall)selfinstancer   Zfeature_name_listr
   r
   r   get_feature_name   s    
z(PriceStrategySerializer.get_feature_namec             C   s   |  }|S )N)get_type_display)r   r   	type_namer
   r
   r   get_type_name   s    z%PriceStrategySerializer.get_type_namec             C   s   |j r|j j}nd}|S )NNone)vendorr   )r   r   vendor_namer
   r
   r   get_vendor_name#   s    
z'PriceStrategySerializer.get_vendor_namec             C   s   |j j}|S )N)create_userZusername)r   r   Zcreate_user_namer
   r
   r   get_create_user_username+   s    z0PriceStrategySerializer.get_create_user_usernamec             C   s   |j jS )N)Zdiscountdiscount_ratio)r   r   r
   r
   r   get_discount_ratio0   s    z*PriceStrategySerializer.get_discount_ratioc               @   sH   e Zd ZeZddddddddd	d
ddddddddddddddddgZdS )zPriceStrategySerializer.Metaidr   r   feature_namer   r   Z*subscription_duration_unit_price_pre_monthZemployee_thresholdZemployee_unit_priceZdevice_thresholdZdevice_unit_priceZ!whatsapp_push_counts_limit_statusZwhatsapp_push_thresholdZwhatsapp_push_unit_priceZmobile_app_counts_limit_statusZmobile_applications_thresholdZmobile_applications_unit_priceZtransaction_counts_limit_statusZtransaction_thresholdZtransaction_unit_pricecountrycurrencycreate_timecreate_user_usernamer   effective_statusN)__name__
__module____qualname__r   modelfieldsr
   r
   r
   r   Meta`   s   r,   N)r'   r(   r)   r   SerializerMethodFieldr   r   r!   r%   r   r   r   r   r   r   r,   r
   r
   r
   r   r	   
   s   	0r	   c                   s2   e Zd Zdd ZG dd dZ fddZ  ZS )PriceStrategyCreateSerializerc             C   sV   | d}| d}| d}| d}| jj}|jj||||d rRtd|S )Ntyper"   r&   r   )r/   r&   r"   vendor__namezZThis price strategy type already existed in this country and in effect and in this vendor.)getr,   r*   objectsfilterexistsr   ValidationError)r   ZattrsZprice_strategy_typecountry_coder&   r   model_classr
   r
   r   validateo   s    



z&PriceStrategyCreateSerializer.validatec               @   s   e Zd ZeZdZdddgZdS )z"PriceStrategyCreateSerializer.Meta__all__r#   r   r$   N)r'   r(   r)   r   r*   r+   read_only_fieldsr
   r
   r
   r   r,   ~   s   r,   c                sd   d }| j d}|r$t|dr$|j}tj}||d< ||d< | jd }t|}||d< tt	| 
|S )Nrequestuserr   r$   r"   r#   )contextr1   hasattrr<   r   ZnowZinitial_datar   superr.   create)r   Zvalidated_datar<   r;   r$   r6   Zcurrency_alpha_3)	__class__r
   r   r@      s    
z$PriceStrategyCreateSerializer.create)r'   r(   r)   r8   r,   r@   __classcell__r
   r
   )rA   r   r.   m   s   r.   c               @   s2   e Zd Zdd Zdd Zdd ZG dd dZd	S )
PriceStrategyEditSerializerc             C   sB   || j jkr>| jj}|jj|d| j j| j jd r>t	
d|S )NT)r/   r&   r"   r   zZThis price strategy type already existed in this country and in effect and in this vendor.)r   r/   r,   r*   r2   r3   r"   r   r4   r   r5   )r   r/   r7   r
   r
   r   validate_type   s    
z)PriceStrategyEditSerializer.validate_typec             C   sB   || j jkr>| jj}|jj|d| j j| j jd r>t	
d|S )NT)r"   r&   r/   r   zZThis price strategy type already existed in this country and in effect and in this vendor.)r   r"   r,   r*   r2   r3   r/   r   r4   r   r5   )r   r"   r7   r
   r
   r   validate_country   s    
z,PriceStrategyEditSerializer.validate_countryc             C   sL   | j jrH|| j jjkrH| jj}|jj|d| j j| j jd	 rHt
d|S )NT)r0   r&   r"   r/   zZThis price strategy type already existed in this country and in effect and in this vendor.)r   r   r   r,   r*   r2   r3   r"   r/   r4   r   r5   )r   r   r7   r
   r
   r   validate_vendor   s    
z+PriceStrategyEditSerializer.validate_vendorc               @   s   e Zd ZeZdZdddgZdS )z PriceStrategyEditSerializer.Metar9   r#   r   r$   N)r'   r(   r)   r   r*   r+   r:   r
   r
   r
   r   r,      s   r,   N)r'   r(   r)   rD   rE   rF   r,   r
   r
   r
   r   rC      s   rC   c               @   s4   e Zd Ze ZeddZdd ZG dd dZ	dS )PriceStrategyFeatureSerializerT)Zmanyc             C   s   |  }|S )N)r   )r   r   r   r
   r
   r   r      s    z,PriceStrategyFeatureSerializer.get_type_namec               @   s   e Zd ZeZdddgZdS )z#PriceStrategyFeatureSerializer.Metar    r   r   N)r'   r(   r)   r   r*   r+   r
   r
   r
   r   r,      s   r,   N)
r'   r(   r)   r   r-   r   r   r   r   r,   r
   r
   r
   r   rG      s   
rG   N)Zrest_frameworkr   Zdjango.utilsr   Zdjango_countries.serializersr   Zmysite.cloud.modelsr   Zmysite.cloud.api.serializersr   Zmysite.cloud.utilsr   r   ZModelSerializerr	   r.   rC   rG   r
   r
   r
   r   <module>   s   c&)