B
    Ac-                 @   s  d dl 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 d
lmZ d dlmZmZmZ G dd deZG dd dejZee
jeddd Zee
jeddd Zddddddddddddddddd e j   d!dd"d#d$ddddddddddddddd e j   d!dd"d%d&ddddddddddd'dddd e j   d!dd"d(d)d*ddddd*ddd*dd'dddd e j   d!dd"gZ!dS )+    N)	Countries)cache)models)settings)signals)receiver)gettext_lazy)CountryField)MyUser)FeatureDiscountCompanyc               @   s   e Zd ZdddZdS )AllowedCountriesZIndiazUnited States of America)INZUSN)__name__
__module____qualname__Zonly r   r   AG:\easytimepro\master/mysite/cloud\models\model_price_strategy.pyr      s   r   c               @   sn  e Zd ZdZejeddZeeZ	ej
dddZejdddZej
dddZejdddZej
dddZejddZejdddZej
dddZejddZejdddZej
dddZejddZejdddZej
dddZeded	d
ZejddddZej ddZ!ej"e#ej$dZ%ej"e&ej$dZ'ejddZ(ej"e)ddej$dZ*G dd dZ+dd Z,dd Z-dS )PriceStrategy))   z
Free Trial)   ZProfessional)   ZPremium)   Z
Enterpriser   )choicesdefaultF)nullblankT)r   z(select country)r   )Zblank_labelZ	countriesr   r   )Z
max_lengthr   r   )Zauto_now_add)	on_delete)r   r   r   c               @   s   e Zd ZedZdZdS )zPriceStrategy.MetazPrice StrategyZcloudN)r   r   r   _Zverbose_nameZ	app_labelr   r   r   r   Meta?   s   r    c             C   s   d |  t| jjS )Nz{}/{})formatZget_type_displaystrcountryname)selfr   r   r   __str__C   s    zPriceStrategy.__str__c             C   s(   t dt| jjd d }d|}|S )Nr   r   d   z{}% off)introunddiscountZdiscount_ratior!   )r%   Z
percentageZdiscount_percentager   r   r   get_discount_percentageF   s    
z%PriceStrategy.get_discount_percentageN).r   r   r   ZTYPE_CHOICESr   ZSmallIntegerFieldtypeZManyToManyFieldr   featureZ
FloatField*subscription_duration_unit_price_pre_monthZIntegerFieldemployee_thresholdemployee_unit_pricedevice_thresholddevice_unit_priceZBooleanField!whatsapp_push_counts_limit_statuswhatsapp_push_thresholdwhatsapp_push_unit_pricemobile_app_counts_limit_statusmobile_applications_thresholdmobile_applications_unit_pricetransaction_counts_limit_statustransaction_thresholdtransaction_unit_pricer	   r   r#   Z	CharFieldcurrencyZDateTimeFieldcreate_timeZ
ForeignKeyr
   ZCASCADEZcreate_userr   r*   effective_statusr   Zvendorr    r&   r+   r   r   r   r   r      s6   
r   )senderc             K   sD  t jr@ddlm} |rt|jdd |j D |j|jd |j|j	j
|j|jj|jd	}d}|||d d}| }	n|j}
|j	j}d	|
|}||d d d}| }	td
}|	d d }x|D ]|}|d
 }||kr|t }d|}|jdd |j D |j|jd |j|j	j
|j|jj|jd	}|||d d}| }	qW d S )Nr   )!HttpRequestInterfaceForIoTServicec             S   s   g | ]
}|j qS r   )id).0fr   r   r   
<listcomp>V   s    zIsave_or_update_price_strategy_to_subscription_service.<locals>.<listcomp>   )	r,   r-   Zuser_unit_priceZannually_subscription_priceZmonthly_subscription_pricer#   r<   r*   r>   z?https://subscriptiondev.minervaiot.com/api/v1/price_strategies/)bodyparamszWhttps://subscriptiondev.minervaiot.com/api/v1/price_strategies/?type={}&country_name={}application_iddataresultszBhttps://subscriptiondev.minervaiot.com/api/v1/price_strategies/{}/c             S   s   g | ]
}|j qS r   )rA   )rB   rC   r   r   r   rD   s   s    )r   CLOUD_VERSION"mysite.cloud.minerva_iot_interfacer@   r,   r-   allr0   r.   r#   Zalpha3r<   r*   rA   r>   Zpostr$   r!   getr   Zput)r?   instanceZcreatedrawkwargsr@   rF   urlinterface_objectcontentprice_strategy_typeprice_strategy_country_namecurrent_application_idrJ   price_strategyresult_application_idprice_strategy_idr   r   r   5save_or_update_price_strategy_to_subscription_serviceM   sP    




r[   c             K   s   t jrddlm} |j}|jj}d||}||d d d}| }t	d}	|d d }
xD|
D ]<}|d }||	kr^|t
 }d|}||d d d}| }q^W d S )	Nr   )r@   zWhttps://subscriptiondev.minervaiot.com/api/v1/price_strategies/?type={}&country_name={})rF   rG   rH   rI   rJ   zBhttps://subscriptiondev.minervaiot.com/api/v1/price_strategies/{}/)r   rK   rL   r@   r,   r#   r$   r!   rN   r   rA   delete)r?   rO   rQ   r@   rU   rV   rR   rS   rT   rW   rJ   rX   rY   rZ   r   r   r   -delete_price_strategy_to_subscription_service   s"    


r]   r   g        i  g      $@2   g      i@Tg      4@i g      ?r   ZINRz%Y-%m-%d %H:%M:%S)r,   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r#   r<   r=   r>   r   g     @@r   g     @Fr   g     @i'  )"ZdatetimeZdjango_countriesr   Zdjango.core.cacher   Z	django.dbr   Zdjango.confr   Zdjango.db.modelsr   Zdjango.dispatch.dispatcherr   Zdjango.utils.translationr   r   Zdjango_countries.fieldsr	   Zmysite.accounts.modelsr
   Zmysite.cloud.modelsr   r   r   r   ZModelr   Z	post_saver[   Zpost_deleter]   ZnowstrftimeZDEFAULT_PRICE_STRATEGY_PARAMSr   r   r   r   <module>   s   23