o
    hӅi&                     @  s   d dl mZ d dlmZmZmZ d dlZd dlZd dlZ	d dl
Z
d dlZddlmZmZ dZdd	d
Zd ddZd!ddZddd"ddZd#ddZdS )$    )annotations)AnyDictListN   )ZoneOperation	ParamSpecui_delete_timesheet_entriesreturnList[ZoneOperation]c                   C  s   t tdddddd d d d dddddtddd	d
tddddtddddtddd	dtddddtddddtddddtddddgdddgdd	dgS )NzUI Delete Timesheet entrieszbElimina entradas (hours -> 0 + save) usando UI automation. Soporta delete_all e include_protected.UIwriteF)timesheet_butimesheet_user_idtimesheet_user_nametimesheet_date
delete_allinclude_protecteddry_runrawr   stringTz&Business Unit a seleccionar en AroFlo.r   u#   AroFlo User ID (preferido, único).r   z'Nombre completo del usuario (fallback).r   zFecha objetivo (YYYY-MM-DD).r   booleanz"Borra TODO en la fecha (hours->0).r   z/Incluye filas protegidas (solo con delete_all).r   z1Si true, no ejecuta UI; solo preview del comando.r   z4Si true, incluye stdout/stderr completos del runner.
timesheetszBorrar overheads por UIu%   Limpieza de días antes de reinsertarhigh)codelabeldescriptionhttp_methodside_effect
idempotentdefault_paramsparamscategory	use_cases
risk_levelrequires_confirmation)r   OP_UI_DELETEr    r'   r'   U/var/www/html/flask_server/apps/aroflo_connector_app/zones/timesheets/mu_ui_delete.pyget_operations   s>   
r)   operation_codestrboolc                 C  s   | t kS )N)r&   )r*   r'   r'   r(   supports8   s   r-   argv	List[str]Dict[str, Any]c                 C  s   dd| dS )NT
subprocess)r   
invocationr.   r'   )r.   r'   r'   r(   _preview<   s   r3   F)r   r   c                C  sz   t j| dddd}|r|j|j|j| dS |jpd  dd  }|jp&d  dd  }|jd|d|| dS )	NTF)capture_outputtextcheck)
returncodestdoutstderrr.    i
)r7   stdout_tailstderr_tailr.   )r1   runr7   r8   r9   strip
splitlinesjoin)r.   r   procout_tailerr_tailr'   r'   r(   _run_uiD   s   rE   clientr   r!   c                 C  s  t |dd}t |dd}t|dp|dpd }t|dp1|dp1td	p1d }|s9d
}|dpB|d}|sItd|dpR|d}|r[t| s_tdt|dpk|dpkd }	t|dp{|dp{d }
|	s|
std| tkr|t|t||	|
t |ddt |ddd}|rdd| d|dS tj	j
| dt|dddid d!}tj	j|d"d#}| d}W d    n1 sw   Y  d$|d|jd%S td&|  )'Nr   Fr   	tenant_idz	tenant-idr:   
worker_urlz
worker-urlAROFLO_UI_WORKER_URLzhttp://127.0.0.1:5010r   ztimesheet-datez)timesheet_date es requerido (YYYY-MM-DD).r   ztimesheet-buz:timesheet_bu es requerido (ej: 'Utility Solutions Group').r   ztimesheet-user-idr   ztimesheet-user-namezDDebes enviar timesheet_user_id o timesheet_user_name (al menos uno).r   r   )rG   r   r   r   r   r   r   Thttpz/ui/timesheets/delete)r   r2   urlpayloadzutf-8zContent-Typezapplication/jsonPOST)dataheadersmethodx   )timeoutr   )r7   r8   r9   rK   u3   [Timesheets.mu_ui_delete] Operación no soportada: )r,   getr+   r?   osgetenv
ValueErrorr&   urllibrequestRequestjsondumpsencodeurlopenreaddecodefull_url)r*   rF   r!   r   r   rG   rH   r   r   r   r   rL   reqrespbodyr'   r'   r(   executeW   sT    *  
rd   )r
   r   )r*   r+   r
   r,   )r.   r/   r
   r0   )r.   r/   r   r,   r
   r0   )r*   r+   rF   r   r!   r0   r
   r   )
__future__r   typingr   r   r   rZ   rT   urllib.requestrW   sysr1   baser   r   r&   r)   r-   r3   rE   rd   r'   r'   r'   r(   <module>   s    

(
