File size: 716 Bytes
846683d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from .entities import Ticket
from .models import Action


VALID_TRANSITIONS = {
    "triage": "in_progress",
    "respond": "in_progress",
    "resolve": "resolved",
    "escalate": "in_progress",
}


def apply_action(ticket: Ticket, action: Action) -> Ticket:
    updated = ticket.model_copy(deep=True)
    updated.attempts_used += 1

    if action.action_type in VALID_TRANSITIONS:
        updated.status = VALID_TRANSITIONS[action.action_type]

    if updated.attempts_used >= updated.max_attempts and updated.status != "resolved":
        updated.status = "open"

    return updated


def is_terminal(ticket: Ticket) -> bool:
    return ticket.status == "resolved" or ticket.attempts_used >= ticket.max_attempts