
    	]j|                         d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
mZ  edddd	
       G d de
             Z eddd	d	
       G d de
             Z eddd	d	
       G d de
             Zy)a[  
FSM Transitions for Task model.

This module defines declarative transitions for the Task entity.

Note: Most task state transitions (annotation_started, annotation_complete, completed)
are triggered by Annotation changes, not Task field changes. Those are handled by
annotation transitions via post_transition_hooks that update the parent task.
    )AnyDictOptional)register_state_transition)TaskStateChoices)ModelChangeTransitionTransitionContexttasktask_createdTF)triggers_on_createtriggers_on_updatec                   R    e Zd ZdZddee   defdZdedefdZdede	ee
f   fdZy)	TaskCreatedTransitionag  
    Transition when a new task is created.

    This is the initial state transition that occurs when a task is
    first saved to the database.

    Trigger: Automatically on creation (triggers_on_create=True)

    Note: Other task transitions (annotation_started, completed, etc.) are
    triggered by Annotation model changes, not Task field changes.
    Ncontextreturnc                 "    t         j                  S N)r   CREATEDselfr   s     K/root/env/lib/python3.12/site-packages/label_studio/fsm/task_transitions.pyget_target_statez&TaskCreatedTransition.get_target_state    s    '''    c                      y)z)Return detailed reason for task creation.zTask created in the system r   s     r   
get_reasonz TaskCreatedTransition.get_reason#   s    +r   c                     |j                   }|j                  |j                  r%t        |j                  j	                               dS g dS )z
        Execute task creation transition.

        Args:
            context: Transition context containing task and user information

        Returns:
            Context data to store with the state record
        )
project_id	data_keys)entityr   datalistkeysr   r   r
   s      r   
transitionz TaskCreatedTransition.transition'   sF     ~~ //3799diinn./
 	
BD
 	
r   r   __name__
__module____qualname____doc__r   r	   strr   r   r   r   r%   r   r   r   r   r      sP    
(1B(C (s (,"3 , ,
"3 
S#X 
r   r   task_completedc                   R    e Zd ZdZddee   defdZdedefdZdede	ee
f   fdZy)	TaskCompletedTransitionz
    Transition when task moves to COMPLETED state.

    Triggered when: First annotation is submitted on this task
    From: CREATED -> COMPLETED or IN_PROGRESS -> COMPLETED
    Nr   r   c                 "    t         j                  S r   )r   	COMPLETEDr   s     r   r   z(TaskCompletedTransition.get_target_stateF   s    )))r   c                      y)Nz%Task completed - annotation submittedr   r   s     r   r   z"TaskCompletedTransition.get_reasonI   s    6r   c                     |j                   }|j                  |j                  |j                  |j                  |j
                  dS N)task_idr   total_annotationscancelled_annotations
is_labeledr    idr   r5   r6   r7   r$   s      r   r%   z"TaskCompletedTransition.transitionL   <    ~~ww//!%!7!7%)%?%?//
 	
r   r   r&   r   r   r   r.   r.   =   sP    *1B(C *s *7"3 7 7
"3 
S#X 
r   r.   task_in_progressc                   R    e Zd ZdZddee   defdZdedefdZdede	ee
f   fdZy)	TaskInProgressTransitionz
    Transition when task moves to IN_PROGRESS state.

    Triggered when: All annotations are deleted from a completed task
    From: COMPLETED -> IN_PROGRESS
    Nr   r   c                 "    t         j                  S r   )r   IN_PROGRESSr   s     r   r   z)TaskInProgressTransition.get_target_state`   s    +++r   c                      y)Nz/Task moved to in progress - annotations deletedr   r   s     r   r   z#TaskInProgressTransition.get_reasonc   s    @r   c                     |j                   }|j                  |j                  |j                  |j                  |j
                  dS r3   r8   r$   s      r   r%   z#TaskInProgressTransition.transitionf   r:   r   r   r&   r   r   r   r=   r=   W   sS    ,1B(C ,s ,A"3 A A
"3 
S#X 
r   r=   N)r*   typingr   r   r   fsm.registryr   fsm.state_choicesr   fsm.transitionsr   r	   r   r.   r=   r   r   r   <module>rF      s    ' & 2 . D 6>d_de#
1 #
 f#
T 6#3bgh
3 
 i
2 6#5%dij
4 
 k
r   