
    i>                         d dl mZ ddlmZmZ dddddd	Z G d
 dej                        Z G d dej                        Zy)    )serializers   )StructureCityTaxSettingsCityTaxMonthlyRateMedicalStudentRefugeeResidentMinor)medicalstudentrefugeeresidentminorc                   &    e Zd Z G d d      Zd Zy)"CityTaxMonthlyRateNestedSerializerc                       e Zd ZeZg dZy)'CityTaxMonthlyRateNestedSerializer.Meta)yearmonthrateN)__name__
__module____qualname__r   modelfields     +/backend/structures/serializers_city_tax.pyMetar      s    "*r   r    c                 J    d|cxk  rdk  sn t        j                  d      |S )Nr      zMonth must be between 1 and 12)r   ValidationError)selfvalues     r   validate_monthz1CityTaxMonthlyRateNestedSerializer.validate_month   s&    ER--.NOOr   N)r   r   r   r    r&   r   r   r   r   r      s    + +r   r   c                   R    e Zd Z edd      Z G d d      Zd Zd Zd Zd	 Z	d
 Z
y)"StructureCityTaxSettingsSerializerTF)manyrequiredc                       e Zd ZeZg dZy)'StructureCityTaxSettingsSerializer.Meta)default_ratemax_taxable_nightsminor_age_limitexemption_reasonsplatform_exemptions
city_taxes	is_activeN)r   r   r   r   r   r   r   r   r   r    r,       s    (
r   r    c                 4   |d t         j                  fv rg S g }|D ]^  }t        |      j                         j	                         }|t
        vrt        j                  d      |j                  t
        |          ` t        t        j                  |            S )NzFExemption reasons must be one of: Medical, Student, Refugee, Resident.)r   emptystrstriplowerEXEMPTION_REASON_LABELSr#   appendlistdictfromkeys)r$   r%   
normalizedreason
reason_keys        r   validate_exemption_reasonsz=StructureCityTaxSettingsSerializer.validate_exemption_reasons,   s    T;,,--I
FV**,224J!88!11\  5jAB  DMM*-..r   c                    |d t         j                  fv rg S |D cg c]C  }t        |      j                         st        |      j                         j	                         E }}t        t        j                  |            S c c}w )N)r   r5   r6   r7   r8   r;   r<   r=   )r$   r%   itemr>   s       r   validate_platform_exemptionsz?StructureCityTaxSettingsSerializer.validate_platform_exemptions;   si    T;,,--I<AWEDSY__EVc$ioo'--/E
WDMM*-.. Xs
   B)Bc                     |j                  dg       }| j                  d   }t        j                  j                  dd|i|}| j                  |||       |S )Nr2   	structurer   )popcontextr   objectscreate_save_city_taxes)r$   validated_datar2   rF   settingss        r   rJ   z)StructureCityTaxSettingsSerializer.createB   sa    #''b9
LL-	+33:: 



 	h	:>r   c                 B   |j                  dd       }|j                         D ]  \  }}t        |||        |j                          |Ut        j
                  j                  |j                        j                          | j                  ||j                  |       |S )Nr2   )rF   )
rG   itemssetattrsaver   rI   filterrF   deleterK   )r$   instancerL   r2   attrr%   s         r   updatez)StructureCityTaxSettingsSerializer.updateN   s    #''d;
)//1KD%HdE* 2 	!&&--",, . fh!!(H,>,>
Kr   c           	      l    |D ]/  }t         j                  j                  |||d   |d   |d          1 y )Nr   r   r   )rF   rM   r   r   r   )r   rI   rJ   )r$   rM   rF   r2   taxs        r   rK   z3StructureCityTaxSettingsSerializer._save_city_taxes`   s@    C&&--#!['l[ .  r   N)r   r   r   r   r2   r    rA   rD   rJ   rV   rK   r   r   r   r(   r(      s5    3J


 

//
$r   r(   N)	rest_frameworkr   modelsr   r   r9   ModelSerializerr   r(   r   r   r   <module>r\      sL    &  )D)D N)D)D Nr   