
    V
h                         S SK J r   S SKJrJr  S SKJr  S SKJr  S SKJ	r	  S SK
JrJr  SrS\S	\R                  S
\4S jrS\S\S\\   S\\   S	\R                  S
\\   4S jrS\S\S	\R                  S
\\   4S jrg)    )datetime)
CollectionReturnDocument)database)AuditLogCreate)str_to_objectid)OptionalList
audit_logs	audit_logdbreturnc                    #    U[            nU R                  5       n[        R                  " 5       US'   UR	                  U5      n[        UR                  5      US'   US   US'   U$ 7f)z?
Insert a new audit log record into the audit_logs collection.
	timestamp_idaudit_id)COLLECTION_NAMEdictr   utcnow
insert_onestrinserted_id)r   r   audit_collectionlog_dataresults        HC:\Suresh\moveshuttle\MDcreated\moveengine\app\v1\services\saas\audit.pycreate_audit_log_servicer   
   sf      $&o#6~~H$OO-H[((2F&,,-HUO#E?HZOs   A%A'skiplimit
account_iduser_idc                 F  #    U[            n0 nU(       a  X&S'   U(       a  X6S'   UR                  U5      R                  U 5      R                  U5      R	                  SS5      n/ nU  Sh  vN n	[        U	S   5      U	S'   U	S   U	S'   UR                  U	5        M5   N0
 U$ 7f)z
Retrieve a paginated list of audit logs.
If account_id or user_id is provided, filters are applied; otherwise, global logs are returned.
r    r!   r   Nr   r   r   findr   r   sortr   append)
r   r   r    r!   r   r   querycursorlogsdocs
             r   list_audit_logs_servicer,      s     
 $&o#6E(l"i""5)..t4::5AFF{TVWFD cU_E
e*JCV Ks*   A%B!'B+B,B/-B!BB!c                   #    U[            nUR                  0 5      R                  U 5      R                  U5      R	                  SS5      n/ nU  Sh  vN n[        US   5      US'   US   US'   UR                  U5        M5   N0
 U$ 7f)z<
Retrieve a paginated list of all audit logs (global view).
r   r#   Nr   r   r$   )r   r   r   r   r)   r*   r+   s          r   list_global_audit_logs_servicer.   )   s      $&o#6""2&++D177>CCKQSTFD cU_E
e*JCV Ks*   AB	BBB-B	BB	N)r   pymongo.collectionr   r   app.dbr   app.v1.models.saas.auditmodelr   app.v1.libraries.objectr   typingr	   r
   r   MongoDBr   r   intr   r,   r.        r   <module>r8      s     9  8 3 !
n 
(BRBR 
W[ 
 C Xc] ]efi]j px  qA  qA   FJ  KO  FP &s 3 HDTDT Y]^bYc r7   