o
    l2i                     @   sf   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	Zd
S )    )datetime)get_db)hash_password)GenericError)User)Staff)StaffResponsec                   @   sP   e Zd Zdd Zdd ZdefddZdefdd	Zd
d Zdd Z	dd Z
dS )StaffServicec                 C   s   t  L}z |jdgd}t|j|d< tdi |}|| |  W n ty> } zt| |	  W Y d }~nd }~ww W d    d S W d    d S 1 sRw   Y  d S )Npasswordexcludehashed_password )
r   
model_dumpr   r
   r   addcommit	Exceptionprintrollback)selfrequestdbpayloadZ	new_staffer   r   /app/services/staff.pycreate_new_staff   s    
	"zStaffService.create_new_staffc                 C   sT   t  }|ttjd  }dd |D W  d    S 1 s#w   Y  d S )Nc                 S   s   g | ]	}t | qS r   )r   model_validater   ).0recordr   r   r   
<listcomp>   s    z1StaffService.fetch_all_staffs.<locals>.<listcomp>)r   queryr   where
deleted_atis_all)r   r   recordsr   r   r   fetch_all_staffs   s   $zStaffService.fetch_all_staffsstaff_idc                 C   l   t  )}|ttj|ktjd  }|stdddt	
| W  d    S 1 s/w   Y  d S N  Staff not foundstatus_codeexcr   r    r   r!   idr"   r#   firstr   r   r   r   r   r'   r   r   r   r   r   fetch_staff_detail       

$zStaffService.fetch_staff_detailc                 C   r(   r)   r/   r2   r   r   r   get_staff_profile_detail+   r4   z%StaffService.get_staff_profile_detailc                 C   s   |j dgd}t 2}|ttj|k }|s tddd|j|_|j	|_	|j
|_
|j|_|  W d    d S 1 s?w   Y  d S Nr0   r   i  zCould not update teacherr,   )r   r   r    r   filterr0   r1   r   
first_name	last_nameemailmobile_numberr   r   r'   r   r   r   staffr   r   r   update_staff6   s   
"zStaffService.update_staffc                 C   s   |j dgd}t 6}|ttj|k }|s tddd|j|_|j	|_	|j
|_
|j|_|j|_|  W d    d S 1 sCw   Y  d S r6   )r   r   r    r   r7   r0   r1   r   r8   r9   r:   r;   
dbs_statusr   r<   r   r   r   update_staff_profileD   s   
"z!StaffService.update_staff_profilec                 C   sj   t  }|ttj|k }|stdddW d    n1 s#w   Y  t |_	|
  ddiS )Nr*   r+   r,   messagezStaff deleted successfully)r   r    r   r7   r0   r1   r   r   nowr"   r   )r   r'   r   r=   r   r   r   delete_staffS   s   
zStaffService.delete_staffN)__name__
__module____qualname__r   r&   intr3   r5   r>   r@   rC   r   r   r   r   r	      s    r	   N)r   core.configr   core.security.authenticationr   core.security.exceptionsr   modelsr   Zmodels.staffr   schema.staffr   r	   r   r   r   r   <module>   s    