
    n4h                         d dl mZmZmZ d dlmZ d dlmZmZmZ d dl	m
Z
mZ d dlmZ d dlmZmZmZ  G d deee
f         Zy	)
    )OptionalDictAny)Session)datetimedate	timedelta)AppointmentService)BaseRepository)AppointmentSchemaCreateAppointmentRequestAppointmentResponseSchemac                        e Zd Zdef fdZdedee   fdZdedefdZ	dede
dee   fd	Z	 ddede
de
de
dededede
d
z  defdZ	 	 	 ddedededed
z  dee
ef   f
dZdededefdZ xZS )AppointmentRepositorydbc                 .    t         |   |t               y N)super__init__r
   )selfr   	__class__s     Q/var/www/html/phonemate/phone_mate_backend/repositories/appointment_repository.pyr   zAppointmentRepository.__init__   s    [)    db_modelreturnc                     t        |j                  |j                  |j                  |j                  |j
                  |j                  |j                  |j                  |j                  |j                  |j                  |j                        S )N)idappointment_no
company_idnamephonestart_datetimeend_datetimesummary
service_idstatus
created_at
updated_at)r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   )r   r   s     r   
_to_entityz AppointmentRepository._to_entity   ss     {{%44**..#22!..$$**??****
 	
r   entityc                     t        |j                  |j                  |j                  |j                  |j
                  |j                  |j                  |j                  |j                  	      S )N)	r    r   r!   r"   r#   r$   r%   r&   r'   )
r
   r    r   r!   r"   r#   r$   r%   r&   r'   )r   r+   s     r   _to_db_modelz"AppointmentRepository._to_db_model!   sX    ((#22,,!00,,NN((==

 
	
r   service_namec                     t        |j                  |j                  |j                  |j                  |j
                  |j                  |j                  ||j                  	      S )N)	r   r!   r   r"   r#   r$   r%   r.   r'   )	r   r   r!   r   r"   r#   r$   r%   r'   )r   r   r.   s      r   _to_responsez"AppointmentRepository._to_response.   sR    ({{%44..#22!..$$%??

 
	
r   Nr    r   r!   r"   r#   r$   r&   r%   c	           
        K   t        ||||||||      }	| j                  j                  |	       | j                  j                          | j                  j	                  |	       | j                  j                  t              j                  t        j                  |k(        j                         }
| j                  |	|
r|
j                        S d      S w)N)r    r   r!   r"   r#   r$   r&   r%   Unknown Service)r
   r   addcommitrefreshqueryr   filterr   firstr0   r!   )r   r    r   r!   r"   r#   r$   r&   r%   appointmentservices              r   create_appointmentz(AppointmentRepository.create_appointment;   s      "!))%!	
 	K $ ''--(//

j0HIOOQ  ggll]]K\]]s   CCstartlimitappointment_datec                 F  K   | j                   j                  t              j                  t        j                  |k(        }|rA|j                  t        j
                  |k\  t        j
                  |t        d      z   k        }|j                         }|j                  |      j                  |      j                         }g }|D ]  }	| j                   j                  t              j                  t        j                  |	j                  k(        j                         }
|j                  |	j                  |	j                   |	j"                  |	j$                  |	j
                  |	j&                  |	j(                  |
r|
j                   nd|	j*                  d	        ||dS w)N   )daysr2   )	r   r!   r"   r   r#   r$   r%   r.   r'   )datatotal_count)r   r6   r
   r7   r    r#   r	   countoffsetr=   allr   r   r&   r8   appendr!   r"   r   r$   r%   r'   )r   r    r<   r=   r>   r6   totalresultsformatted_appointmentsr9   r:   s              r   get_by_companyz$AppointmentRepository.get_by_companyX   sT     k*11+2H2HJ2VWLL**.>>**-=	q@Q-QQE
 ,,u%++E2668!#"KggmmG,33GJJ+BXBX4XY__aG"))!nn#(($**"-"<"<"-"<"< + 8 8&..07=N%,,
+ 
 # + 
 	
s   FF!appointment_idc                   K   | j                   j                  t              j                  t        j                  |k(  t        j
                  |k(        j                         }|syd|_        | j                   j                          yw)NF   T)	r   r6   r
   r7   r   r    r8   r'   r4   )r   rL   r    r9   s       r   cancel_appointmentz(AppointmentRepository.cancel_appointment   sj     ggmmK077NNn,""j0
 %' 	
 s   BBr   )r   
   N)__name__
__module____qualname__r   r   r
   r   r   r*   r-   strr   r0   intr   r;   r   r   r   rK   boolrO   __classcell__)r   s   @r   r   r      s5   *7 *
; 
8<M3N 
 
#4 
 

[ 
 
QjHk 
, #^^ ^ 	^
 ^ !^ ^ ^ t^ 
#^@ (,%
%
 %
 	%

 +%
 
c3h%
Ns  PT r   r   N)typingr   r   r   sqlalchemy.ormr   r   r   r	   modelsr
   r   repositories.base_repositoryr   schemas.appointmentr   r   r   r    r   r   <module>r^      s=    & & " . . ' 7 }N+<k+IJ }r   