o
    di<                     @   sx   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 G dd	 d	eZG d
d deZdS )    status)IsAuthenticated)Response)APIView)models)station_bookmark_serializers)BaseModelViewSetc                   @   sB   e Zd ZdZejZejj	
 Zg dZdd Zdd Zdd Zd	S )
StationBookmarkModelViewSeta  
    This is the StationBookmarkModelViewSet class responsible for managing bookmarked stations.

    It provides endpoints for creating, retrieving, and removing bookmarked stations.

    Attributes:
        permission_classes (tuple): Specifies the permissions required to access this view
        (IsAuthenticated for authenticated users).
        serializer_class: The serializer class used for handling station bookmark data.
        queryset (QuerySet): The queryset for accessing bookmarked station records.
        http_method_names (list): Specifies the supported HTTP methods for this view,
        including 'post', 'get', and 'delete'.
    )postgetdeletec                 C   s   | j j| jjdS )z
        Get the queryset of bookmarked stations for the requesting user.

        This method filters bookmarked station records based on the requesting user.

        Returns:
            QuerySet: The filtered queryset of bookmarked stations.
        user)querysetfilterrequestr   )self r   d/var/www/html/evchargy.com/django-station-ev/station_ev/apps/station/views/station_bookmark_views.pyget_queryset   s   	z(StationBookmarkModelViewSet.get_querysetc                 C   s   |j | jjd dS )z
        Create a new station bookmark and associate it with the requesting user.

        Args:
        serializer (StationBookmarkSerializer): The serializer for creating a new station bookmark.
        r   N)saver   r   )r   
serializerr   r   r   perform_create)   s   z*StationBookmarkModelViewSet.perform_createc                 O   sB   |   }|j|jkrtdditjdS | | tdditjdS )aX  
        Remove a station from the user's bookmarks.

        Args:
        request (HttpRequest): The HTTP request object.
        *args: Variable-length argument list.
        **kwargs: Arbitrary keyword arguments.

        Returns:
            Response: A response indicating the success or failure of the station removal operation.
        messagez#You can't remove other user stationr   z*Station removed from bookmark successfully)
get_objectr   r   r   HTTP_400_BAD_REQUESTperform_destroyHTTP_204_NO_CONTENT)r   r   argskwargsinstancer   r   r   destroy2   s   
z#StationBookmarkModelViewSet.destroyN)__name__
__module____qualname____doc__r   ZStationBookmarkSerializerserializer_classr   BookmarkStationobjectsallr   http_method_namesr   r   r"   r   r   r   r   r
      s    	r
   c                   @   s   e Zd ZdZefZdd ZdS )DeleteBookmarkStationAPIViewzI
    API view to delete a bookmarked station for the logged-in user.
    c                 O   sZ   zt jjj||jd}|  tdditjdW S  t jj	y,   tdditj
d Y S w )a  
        Remove a station from the user's bookmarks.

        Args:
            request (HttpRequest): The HTTP request object.
            station_id (int): The primary key of the associated station.
            *args: Variable-length argument list.
            **kwargs: Arbitrary keyword arguments.

        Returns:
            Response: A response indicating the success or failure of the station removal operation.
        )
station_idr   r   z+Station removed from bookmarks successfullyr   zBookmark not found)r   r(   r)   r   r   r   r   r   r   DoesNotExistHTTP_404_NOT_FOUND)r   r   r-   r   r    Zbookmarked_stationr   r   r   r   U   s   
z#DeleteBookmarkStationAPIView.deleteN)r#   r$   r%   r&   r   permission_classesr   r   r   r   r   r,   N   s    r,   N)rest_frameworkr   Zrest_framework.permissionsr   rest_framework.responser   rest_framework.viewsr   Zapps.stationr   Zapps.station.serializersr   
base.viewsr	   r
   r,   r   r   r   r   <module>   s    C