from datetime import datetime
from config import DEFAULT_INTERVAL_ATTEMPTS, DEFAULT_ASSIGNED_TO_ATTEMPTS

class Ticket(object):
    def __init__(
            self,
            id,
            status,
            ticket_list,
            ticket_type,
            title,
            created_at,
            updated_at,
            due_date,
            priority,
            created_by,
            assigned_to=None,
            note=None,
            json=None,
            available_statuses=None,

            interval_attempts: int = DEFAULT_INTERVAL_ATTEMPTS,
            assigned_to_attempts: int = DEFAULT_ASSIGNED_TO_ATTEMPTS
    ):
        self.id = id
        self.status = status
        self.ticket_list = ticket_list
        self.ticket_type = ticket_type
        self.title = title
        self.created_at = created_at
        self.updated_at = updated_at
        self.due_date = due_date
        self.priority = priority
        self.created_by = created_by
        self.assigned_to = assigned_to
        self.note = note
        self.json = json
        self.available_statuses = available_statuses

        self.interval_attempts = interval_attempts
        self.assigned_to_attempts = assigned_to_attempts

    def __str__(self):
        return "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}".format(
            self.id,
            self.status,
            self.ticket_list,
            self.ticket_type,
            self.title,
            self.created_at,
            self.updated_at,
            self.due_date,
            self.priority,
            self.created_by,
            self.assigned_to,
            self.note,
            self.json,
            self.available_statuses
        )

    def to_dict(self):
        """ Method to convert the object to a dictionary, if needed for JSON responses or serialization """
        return {
            "id": self.id,
            "status": self.status,
            "ticket_list": self.ticket_list,
            "ticket_type": self.ticket_type,
            "title": self.title,
            "created_at": self.created_at,
            "updated_at": self.updated_at,
            "due_date": self.due_date,
            "priority": self.priority,
            "created_by": self.created_by,
            "assigned_to": self.assigned_to,
            "note": self.note,
            "json": self.json,
            "available_statuses": self.available_statuses
        }

    def update_status(self, new_status):
        self.status = new_status
        self.updated_at = datetime.now().isoformat()

    def assign_to(self, user_id):
        self.assigned_to = user_id

    def get_summary(self):
        return f"Ticket '{self.title}' (ID: {self.id}) - Status: {self.status}, Priority: {self.priority}"

