
    \Feo                     "   d dl mZmZmZmZmZ d dlmZ ddlmZm	Z	m
Z
mZ  e	       Z eddgddd	ii
      Zej                  d      dededefd       Zej                  d      dededefd       Zej%                  d      dedefd       Zy)    )	APIRouterDependsHTTPExceptionstatusRequest)datetime   )MONGODB_DATABASEmongodb_connectcheck_accessget_user_subz/matchmatch  descriptionz	Not found)prefixtags	responsesz/like/{profile_sub}/{hotel_sub}requestprofile_sub	hotel_subc                 <  K   | j                   d   j                  d      d   }t        |d       t        |      }t        t
           d   j                  ||dddi      }|st        d	d
      t        t
           d   j                  d|iddi      }|st        d	d      t        t
           d   j                  ||dddi      rt        dd      t        t
           d   j                  ||t        j                         j                         dd       ddiS w)a  
    Match with a hotel

    This endpoint allows a user to match with a hotel. The user must own the profile to be able to match with a hotel. Base for swipe hotels. Called when hotel is swiped right.

    Params: 

        - profile_sub, identifier of a profile
        - hotel_sub, identifier of a hotel

    Return: message indicating that the profiled has matched with the hotel.
    authorization    
MatchHotelprofiler   user_sub_idr   r   SThe profile you are trying to like a hotel from does not exist or you don't own it.status_codedetailrefactor_hotelsr   0The hotel you are trying to like does not exist.r   r   r     The hotel is already liked.Tr   r   	timestampstatemessagezHotel liked.headerssplitr   r   mongodb_clientr
   find_oner   
insert_oner   now	isoformatr   r   r   
auth_tokenmy_subr   hotels          OC:\Users\ChattiNader\Documents\EpsilonGroupe\api-vastappli\app\routers\match.pymatch_hotelr:      s\     177<Q?J\**%F-.y9BBS^lrCsv{}~u  AG  5J  K  	K+,->?HH+W`IadiklcmnE4fgg&'099+dm:nqvxypz{4QRR#$W-88cl  |D  |H  |H  |J  |T  |T  |V  ae  :f  g~&&   DDz"/dislike/{profile_sub}/{hotel_sub}c                 <  K   | j                   d   j                  d      d   }t        |d       t        |      }t        t
           d   j                  ||dddi      }|st        d	d
      t        t
           d   j                  d|iddi      }|st        d	d      t        t
           d   j                  ||dddi      rt        dd      t        t
           d   j                  ||t        j                         j                         dd       ddiS w)a  
    Unmatch a hotel

    This endpoint allows a user to unmatch with a hotel. The user must own the profile to be able to unmatch with a hotel. Base for swipe hotels. Called when hotel is swiped left.

    Params: 

        - profile_sub, identifier of a profile
        - hotel_sub, identifier of a hotel

    Return: message indicating that the profile unmatched with the hotel.
    r   r   r   UnmatchHotelr   r   r   r   r   r    r!   r$   r   r%   r   r&   r'   r(   Fr)   r,   zHotel unmatched.r-   r5   s          r9   unmatch_hotelr>   -   s]     177<Q?J^,*%F-.y9BBS^lrCsv{}~u  AG  5J  K  	K+,->?HH+W`IadiklcmnE4fgg&'099+dm:nqvxypz{4QRR#$W-88cl  |D  |H  |H  |J  |T  |T  |V  af  :g  h)**r;   z/matched/{profile_sub}c           	      n  K   | j                   d   j                  d      d   }t        |d       t        |      }t        t
           d   j                  ||dddi      }|st        d	d
      dd|iiddddddiddiddddddig}t        t        t
           d   j                  |            }d|iS w)a  
    Get matched hotels

    This endpoint returns a list of hotels that a user has matched with. Usefull for the users to see what hotels they have liked.

    Params: profile_sub, identifier of a profile

    Return: list of hotels, each hotel has the following fields:

        - sub: identifier of the hotel
        - name: name of the hotel
        - address: address of the hotel
    r   r   r   GetMatchListr   r   r   r   r   zYThe profile you are trying to get matched hotels from does not exist or you don't own it.r!   z$matchr   z$lookuphotels_datar   subliked_hotels)from
localFieldforeignFieldasz$unwindz$liked_hotelsz$projectz$liked_hotels.subz$liked_hotels.namez$liked_hotels.address)r   rB   nameaddressr   hotels)
r.   r/   r   r   r0   r
   r1   r   list	aggregate)r   r   r6   r7   r   pipelinerJ   s          r9   get_match_listrN   M   s     177<Q?J^,*%F-.y9BBS^lrCsv{}~u  AG  5P  Q  	Q 
M;/0	!%! 	
 	 
O$	&(.	
 	H  .!127;EEhOPFfs   B3B5N)fastapir   r   r   r   r   r   utilsr
   r   r   r   r0   routerpoststrr:   r>   getrN        r9   <module>rW      s    F F  Q Q "	
]K01
 ./'w 'S 'S ' 0'< 12+ +s +s + 3+> $%&' & & &&rV   