§
    ýd»jÅ  ã                   ó€   — d Z ddlmZ ddlmZmZmZ  G d„ dee¦  «        Z G d„ dee¦  «        Z	 G d„ d	¦  «        Z
d
S )zÕ
FreeExile Currency Exchange & Purchasing Power Parity (PPP) Engine.
Calculates localized fiat pricing, exchange rates, web/crypto bonus coin incentives,
and prevents fraudulent cross-border VPN region arbitrage.
é    )ÚEnum)ÚDictÚTupleÚOptionalc                   ó   — e Zd ZdZdZdZdS )ÚRegionalPricingTierÚTIER_1_STANDARDÚTIER_2_MODERATEÚTIER_3_EMERGINGN)Ú__name__Ú
__module__Ú__qualname__r	   r
   r   © ó    ú6C:\Projects\FreeExile\server\shop\currency_exchange.pyr   r      s   € € € € € Ø'€OØ'€OØ'€O€O€Or   r   c                   ó2   — e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
S )ÚFiatCurrencyÚUSDÚVNDÚEURÚGBPÚJPYÚKRWÚCNYÚTHBÚBRLN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s;   € € € € € Ø
€CØ
€CØ
€CØ
€CØ
€CØ
€CØ
€CØ
€CØ
€C€C€Cr   r   c                   óü  — e Zd ZU dZdZddddddd	d
ddœ	Zeeef         e	d<   ddddddddddddœZ
eeef         e	d<   ej        dej        dej        diZeeef         e	d<   ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        dœZeeef         e	d<   dedefd „Zd!edefd"„Zd!edefd#„Zd$ed!edefd%„Z	 d.d$ed'ed(edefd)„Zd*ed+edeeef         fd,„Zd-S )/ÚCurrencyExchangeEnginez[Calculates authoritative FX rates, Purchasing Power Parity adjustments, and reward bonuses.éd   ç      ð?g     jØ@gq=
×£pí?gö(\�Âõè?g     `c@g     •@g      @g      B@g      @)	r   r   r   r   r   r   r   r   r   ÚFX_RATES_PER_USDr   r   r   r   r   r   r   r   r   )ÚUSÚVNÚJPÚKRÚCNÚTHÚDEÚFRÚGBÚBRÚSGÚCOUNTRY_TO_CURRENCYgÍÌÌÌÌÌì?g      à?ÚPPP_MULTIPLIERS)r"   r$   r*   r(   r)   r%   r,   ÚTWr#   r'   ÚIDr+   ÚCOUNTRY_TIERSÚ
usd_amountÚreturnc                 óJ   — t          t          || j        z  ¦  «        ¦  «        S )z5Standard baseline conversion: $1.00 = 100 Gold Cores.)ÚintÚroundÚBASE_COIN_PER_USD)Úselfr2   s     r   Úconvert_usd_to_coinsz+CurrencyExchangeEngine.convert_usd_to_coinsV   s    € å•5˜ dÔ&<Ñ<Ñ=Ô=Ñ>Ô>Ð>r   Úcountry_codec                 óp   — | j                              |                     ¦   «         t          j        ¦  «        S )N)r1   ÚgetÚupperr   r	   ©r8   r:   s     r   Úget_regional_tierz(CurrencyExchangeEngine.get_regional_tierZ   s+   € ØÔ!×%Ò% l×&8Ò&8Ñ&:Ô&:Õ<OÔ<_Ñ`Ô`Ð`r   c                 ó\   — | j                              |                     ¦   «         d¦  «        S )Nr   )r-   r<   r=   r>   s     r   Úget_currency_for_countryz/CurrencyExchangeEngine.get_currency_for_country]   s'   € ØÔ'×+Ò+¨L×,>Ò,>Ñ,@Ô,@À%ÑHÔHÐHr   Úbase_usdc                 ó2  — |                       |¦  «        }| j        |         }|                      |¦  «        }| j                             |d¦  «        }||z  |z  }|dv rt          t          |d¦  «        ¦  «        S t          t          |d¦  «        ¦  «        S )zÂ
        Calculates localized fiat pricing adjusted for regional Purchasing Power Parity (PPP).
        Example: $10 base in VN (PPP 0.50, FX 25,000) = 10 * 25,000 * 0.50 = 125,000 VND.
        r    )r   r   r   éýÿÿÿé   )r?   r.   rA   r!   r<   Úfloatr6   )r8   rB   r:   ÚtierÚ
ppp_factorÚcurrencyÚfx_rateÚ	raw_prices           r   Úcalculate_localized_fiat_pricez5CurrencyExchangeEngine.calculate_localized_fiat_price`   sœ   € ð
 ×%Ò% lÑ3Ô3ˆØÔ)¨$Ô/ˆ
Ø×0Ò0°Ñ>Ô>ˆØÔ'×+Ò+¨H°cÑ:Ô:ˆà˜wÑ&¨Ñ3ˆ	ð Ð,Ð,Ð,Ý�˜y¨"Ñ-Ô-Ñ.Ô.Ð.Ý•U˜9 aÑ(Ô(Ñ)Ô)Ð)r   FÚplatformÚis_web3_cryptoc                 ó„   — |                       |¦  «        }|s|dv r$t          t          |dz  ¦  «        ¦  «        }||z   S |S )z¿
        Calculates final delivered coins.
        Web Direct Store and Web3 Crypto enjoy a +10% bonus incentive because
        they bypass the 30% Apple/Google mobile platform cut.
        )ÚPLATFORM_WEB_PCÚPLATFORM_ANDROID_SIDELOADgš™™™™™¹?)r9   r5   r6   )r8   rB   rM   rN   Ú
base_coinsÚbonus_coinss         r   Úcalculate_coins_rewardz-CurrencyExchangeEngine.calculate_coins_rewardq   sW   € ð ×.Ò.¨xÑ8Ô8ˆ
ð ð 	,˜XÐ)YÐYÐYÝ�e J°Ñ$5Ñ6Ô6Ñ7Ô7ˆKØ Ñ+Ð+àÐr   Ú
ip_countryÚpayment_countryc                 óÀ   — |                      ¦   «                              ¦   «         }|                      ¦   «                              ¦   «         }||k    rdd|› d|› d�fS dS )z¢
        Guards against VPN region-hopping arbitrage.
        If a user with a Tier 1 IP attempts to pay with a Tier 3 subsidized method, reject or flag.
        FzREGION_MISMATCH: IP origin 'z)' does not match payment method country 'ú')TÚREGION_VALID)Ústripr=   )r8   rU   rV   Úip_normÚpm_norms        r   Úvalidate_billing_regionz.CurrencyExchangeEngine.validate_billing_region…   so   € ð ×"Ò"Ñ$Ô$×*Ò*Ñ,Ô,ˆØ!×'Ò'Ñ)Ô)×/Ò/Ñ1Ô1ˆà�gÒÐØÐu¸ÐuÐuÐkrÐuÐuÐuÐuÐuà#Ð#r   N)F)r   r   r   Ú__doc__r7   r!   r   ÚstrrF   Ú__annotations__r-   r   r	   r
   r   r.   r1   r5   r9   r?   rA   rL   ÚboolrT   r   r]   r   r   r   r   r      sz  € € € € € € ØeÐeð Ðð ØØØØØØØØð
*ð 
*Ð�d˜3 ˜:Ô&ð 
ð 
ñ 
ð ØØØØØØØØØØð+ð +Ð˜˜c 3˜hœð ð ñ ð  	Ô+¨TØÔ+¨TØÔ+¨Tð9€O�TÐ-¨uÐ4Ô5ð ð ñ ð "Ô1Ø!Ô1Ø!Ô1Ø!Ô1Ø!Ô1Ø!Ô1Ø!Ô1Ø!Ô1Ø!Ô1Ø!Ô1Ø!Ô1Ø!Ô1ð5ð 5€M�4˜Ð0Ð0Ô1ð ð ñ ð?¨uð ?¸ð ?ð ?ð ?ð ?ða¨cð aÐ6Ið að að að aðI°Sð I¸Sð Ið Ið Ið Ið*°uð *ÈCð *ÐTYð *ð *ð *ð *ð*  %ð	ð àðð ðð ð	ð
 
ðð ð ð ð($àð$ð ð$ð 
ˆt�SˆyÔ	ð	$ð $ð $ð $ð $ð $r   r   N)r^   Úenumr   Útypingr   r   r   r_   r   r   r   r   r   r   ú<module>rd      sÕ   ððð ð Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (ð(ð (ð (ð (ð (˜#˜tñ (ô (ð (ð	ð 	ð 	ð 	ð 	�3˜ñ 	ô 	ð 	ðw$ð w$ð w$ð w$ð w$ñ w$ô w$ð w$ð w$ð w$r   