o
    di                     @   sh   d dl mZ d dlmZ d dlmZ G dd deZG dd deZG dd	 d	eZ	G d
d deZ
dS )    )serializers)models)DynamicFieldsModelSerializerc                   @   &   e Zd ZdZG dd dZdd ZdS )AmenitiesUploadCSVSerializersa  
    This is the AmenitiesCSVUploadSerializers.

    It serializes amenities data from a CSV file.

    Meta:
        model (AmenitiesMaster): The model used for serialization.
        fields (str): The fields to include in the serialization (all fields are included).
    c                   @   s   e Zd ZejZddgZdS )z"AmenitiesUploadCSVSerializers.Metanametype_idN)__name__
__module____qualname__master_modelAmenitiesMastermodelfields r   r   i/var/www/html/evchargy.com/django-station-ev/station_ev/apps/master/serializers/csv_master_serializers.pyMeta   s    r   c                 C   \   | d}|r)tjjj||d\}}|s'| D ]
\}}t||| q|  |S t	dNr   r   defaults+Type Id is required for update or creation.)
getr   r   objectsget_or_createitemssetattrsaver   ValidationError)selfvalidated_datar   amenitycreatedkeyvaluer   r   r   create      

z$AmenitiesUploadCSVSerializers.createNr	   r
   r   __doc__r   r%   r   r   r   r   r          
r   c                   @   r   )ConnectorCSVUploadSerializersa  
    This is the ConnectorCSVUploadSerializers.

    It serializes connector data from a CSV file.

    Meta:
        model (ConnectorMaster): The model used for serialization.
        fields (str): The fields to include in the serialization (all fields are included).
    c                   @      e Zd ZejZdZdS )z"ConnectorCSVUploadSerializers.Meta__all__N)r	   r
   r   r   ConnectorMasterr   r   r   r   r   r   r   6       r   c                 C   r   r   )
r   r   r-   r   r   r   r   r   r   r   r   r    r   stationr"   r#   r$   r   r   r   r%   :   r&   z$ConnectorCSVUploadSerializers.createNr'   r   r   r   r   r*   +   r)   r*   c                   @   r   )LocationsCSVUploadSerializersa  
    This is the LocationsCSVUploadSerializers class responsible for serializing and deserializing location data.

    It allows users to manage the upload of location data from a CSV file and the creation or update of location records.

    Meta:
        model (LocationMaster): The model used for serialization and deserialization.
        fields (str): The fields to include in the serialization (all fields are included).
    c                   @   r+   )z"LocationsCSVUploadSerializers.Metar,   N)r	   r
   r   r   LocationMasterr   r   r   r   r   r   r   Z   r.   r   c                 C   r   )a  
        Create or update a location record based on the 'type_id' field.

        Args:
            validated_data (dict): Validated data containing location details.

        Returns:
            LocationMaster: The created or updated location record.
        r   r   r   )
r   r   r2   r   r   r   r   r   r   r   r/   r   r   r   r%   ^   s   

z$LocationsCSVUploadSerializers.createNr'   r   r   r   r   r1   O   r)   r1   c                   @   r   )#NetworkOperatorUploadCSVSerializersa>  
    This serializer is used for creating or updating network operator records from CSV data.

    Attributes:
        class Meta: Specifies the model and fields to include in the serialization.

    Methods:
        create(validated_data): Create or update a network operator record based on the 'type_id' field.
    c                   @   r+   )z(NetworkOperatorUploadCSVSerializers.Metar,   N)r	   r
   r   r   NetworkOperatorMasterr   r   r   r   r   r   r      r.   r   c                 C   r   )a  
        Create or update a network operator record based on the 'type_id' field.

        Args:
            validated_data (dict): Validated data containing network operator details.

        Returns:
            NetworkOperatorMaster: The created or updated network operator record.

        Raises:
            serializers.ValidationError: If 'type_id' is missing in the input data.
        r   r   r   )
r   r   r4   r   r   r   r   r   r   r   )r   r    r   ZnetworkOperatorr"   r#   r$   r   r   r   r%      s    
z*NetworkOperatorUploadCSVSerializers.createNr'   r   r   r   r   r3   }   r)   r3   N)rest_frameworkr   Zapps.masterr   r   base.serializersr   r   r*   r1   r3   r   r   r   r   <module>   s    $$.