o
    î|ik   ã                   @   s^   d dl mZ d dl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	d
S )é    )Úserializers)ÚVehiclePricing)ÚVehiclec                   @   s  e Zd ZdZejdd�Zejdd�Zejdd�Z	ejdd�Z
ejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejddgddd�Zdd	„ Zd
S )ÚVehiclePricingCreateSerializerze
    Serializer for creating Vehicle Pricing.
    Connects directly to Vehicle (via vehicle_id).
    T©ÚrequiredÚASSIGNEDÚNOT_ASSIGNEDF©Úchoicesr   Údefaultc                 C   s`   |  dd ¡}|  dd ¡ z	tjj|d�}W n tjy$   t ddi¡‚w tjjdd|i|¤ŽS )NÚ
vehicle_idÚvehicle)ÚidzInvalid vehicle ID.© )	Úpopr   ÚobjectsÚgetÚDoesNotExistr   ÚValidationErrorr   Úcreate)ÚselfÚvalidated_datar   r   r   r   ú@/var/www/html/Moveonwheels/move_on_wheels/pricing/serializers.pyr   5   s   ÿz%VehiclePricingCreateSerializer.createN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú	CharFieldr   Ú
FloatFieldÚhourly_price_sÚhourly_price_mÚhourly_price_lÚhourly_base_km_sÚhourly_base_km_mÚhourly_base_km_lÚhourly_extra_price_per_km_sÚhourly_extra_price_per_km_mÚhourly_extra_price_per_km_lÚmonthly_price_sÚmonthly_price_mÚmonthly_price_lÚmonthly_base_km_sÚmonthly_base_km_mÚmonthly_base_km_lÚmonthly_extra_price_per_km_sÚmonthly_extra_price_per_km_mÚmonthly_extra_price_per_km_lÚChoiceFieldÚstatusr   r   r   r   r   r   	   s6    ýr   c                   @   sp   e Zd ZdZe ¡ 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S )ÚVehiclePricingListSerializerzž
    Serializer for listing all Vehicles with their pricing information.
    If a vehicle does not have assigned pricing, it shows 'NOT_ASSIGNED' status.
    c                 C   s   t t|dd ƒƒp	dS )Nr   z
Unknown ID)ÚstrÚgetattr©r   Úobjr   r   r   Úget_vehicle_idT   s   z+VehiclePricingListSerializer.get_vehicle_idc                 C   ó*   t |dƒr|jrt|jddƒS t|ddƒS )NÚmodelÚnamezUnknown ModelÚ
model_name)Úhasattrr;   r6   r7   r   r   r   Úget_model_nameW   ó   z+VehiclePricingListSerializer.get_model_namec                 C   r:   )NÚpickup_pointr<   zUnknown PickupÚpickup_point_name)r>   rA   r6   r7   r   r   r   Úget_pickup_point_name\   r@   z2VehiclePricingListSerializer.get_pickup_point_namec                 C   s   t |dd ƒ}t |ddƒS )NÚpricingr3   r	   )r6   ©r   r8   rD   r   r   r   Ú
get_statusd   s   z'VehiclePricingListSerializer.get_statusc                 C   óJ   t |dd ƒ}|s
dS |j|j|jdœ|j|j|jdœ|j|j|j	dœdœS ©NrD   zNot assigned)ÚpriceÚbase_kmÚextra_per_km)ÚsmallÚmediumÚlarge)
r6   r    r#   r&   r!   r$   r'   r"   r%   r(   rE   r   r   r   Ú
get_hourlyh   ó    ýýýõz'VehiclePricingListSerializer.get_hourlyc                 C   rG   rH   )
r6   r)   r,   r/   r*   r-   r0   r+   r.   r1   rE   r   r   r   Úget_monthly   rP   z(VehiclePricingListSerializer.get_monthlyN)r   r   r   r   r   ÚSerializerMethodFieldr   r=   rB   r3   ÚhourlyÚmonthlyr9   r?   rC   rF   rO   rQ   r   r   r   r   r4   D   s    r4   c                       s"  e Zd ZdZejddd�Zejddgddd�Zej	dd	�Z
ej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zej	dd	�Zd
d„ Z‡ fdd„Z‡  ZS )ÚVehiclePricingDetailSerializerzy
    Detailed serializer for Vehicle Pricing.
    Displays full pricing fields and reads related names from Vehicle.
    z
vehicle.idT)ÚsourceÚ	read_onlyr   r	   Fr
   r   c                 C   s*   |  ¡ D ]
\}}t|||ƒ q| ¡  |S )z$Manual update for MongoEngine model.)ÚitemsÚsetattrÚsave)r   Úinstancer   ÚfieldÚvaluer   r   r   ÚupdateÉ   s   z%VehiclePricingDetailSerializer.updatec                    s4   t ƒ  |¡}t|jddƒ|d< t|jddƒ|d< |S )z+Add human-readable related vehicle details.r=   NrB   )ÚsuperÚto_representationr6   r   )r   r8   Údata©Ú	__class__r   r   r`   Ó   s   z0VehiclePricingDetailSerializer.to_representation)r   r   r   r   r   r   r   r2   r3   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r^   r`   Ú__classcell__r   r   rb   r   rU   š   s8    ý	
rU   N)
Úrest_frameworkr   Úpricing.modelsr   Úvehicles.modelsr   Ú
Serializerr   r4   rU   r   r   r   r   Ú<module>   s    ;V