"""
TaskManager
Generated by Eden via recursive self-improvement
2025-10-27 17:23:54.756016
"""

class TaskManager:
    """
    A class to manage tasks with attributes like title, priority, deadline, and tags.
    
    Methods:
        __init__(): Initializes the task manager with an empty list of tasks.
        create_task(title, priority, deadline, tags): Creates a new task with given parameters.
        get_all_tasks(): Returns all tasks in the system.
        get_task_by_id(task_id): Retrieves a task by its unique ID.
        update_task(task_id, **kwargs): Updates task attributes based on provided arguments.
        delete_task(task_id): Removes a task from the system.
        filter_tasks_by_tag(tag_name): Filters tasks by a specific tag.
    """
    
    def __init__(self):
        self.tasks = []
        
    def create_task(self, title, priority, deadline=None, tags=None):
        """
        Creates a new task with given parameters.
        
        Args:
            title (str): The title of the task.
            priority (int): Priority level from 0 to 5.
            deadline (str, optional): Deadline date in 'YYYY-MM-DD' format.
            tags (list, optional): List of tag names for categorization.
        """
        if tags is None:
            tags = []
        new_task = {
            "id": len(self.tasks) + 1,
            "title": title,
            "priority": priority,
            "deadline": deadline,
            "tags": tags
        }
        self.tasks.append(new_task)
        return f"Task {new_task['id']} created successfully."
    
    def get_all_tasks(self):
        """Returns all tasks in the system."""
        return self.tasks.copy()
    
    def get_task_by_id(self, task_id):
        """
        Retrieves a task by its unique ID.
        
        Args:
            task_id (int): The ID of the task to retrieve.
            
        Returns:
            dict or None: The task if found, otherwise None.
        """
        for task in self.tasks:
            if task['id'] == task_id:
                return task
        return None
    
    def update_task(self, task_id, **kwargs):
        """
        Updates task attributes based on provided arguments.
        
        Args:
            task_id (int): The ID of the task to update.
            kwargs: Dictionary containing new values for fields like title, priority, deadline, tags.
            
        Returns:
            str: Success message if update is successful.
        """
        for task in self.tasks:
            if task['id'] == task_id:
                for key, value in kwargs.items():
                    if key in task:
                        task[key] = value
                return f"Task {task_id} updated successfully."
        return f"Task with ID {task_id} not found."
    
    def delete_task(self, task_id):
        """
        Removes a task from the system.
        
        Args:
            task_id (int): The ID of the task to delete.
            
        Returns:
            str: Success message if deletion is successful.
        """
        for index, task in enumerate(self.tasks):
            if task['id'] == task_id:
                del self.tasks[index]
                return f"Task {task_id} deleted successfully."
        return f"Task with ID {task_id} not found."
    
    def filter_tasks_by_tag(self, tag_name):
        """
        Filters tasks by a specific tag.
        
        Args:
            tag_name (str): The name of the tag to filter by.
            
        Returns:
            list: List of tasks containing the specified tag.
        """
        filtered = []
        for task in self.tasks:
            if tag_name in task['tags']:
                filtered.append(task)
        return filtered
    
    def get_high_priority_tasks(self):
        """Returns tasks with high priority (priority level 5)."""
        return [task for task in self.tasks if task['priority'] == 5]
    
    def get_overdue_tasks(self):
        """Returns tasks that are overdue based on their deadline."""
        from datetime import date
        today = date.today().isoformat()
        return [task for task in self.tasks if task.get('deadline') and 
                task['deadline'] < today]

# Example usage:
if __name__ == "__main__":
    print("Welcome to Task Manager!")
    manager = TaskManager()
    
    while True:
        print("\nOptions:")
        print("1. Add Task")
        print("2. List All Tasks")
        print("3. Get Task by ID")
        print("4. Update Task")
        print("5. Delete Task")
        print("6. Filter by Tag")
        print("7. Show High Priority Tasks")
        print("8. Show Overdue Tasks")
        print("9. Exit")
        
        choice = input("\nEnter your choice: ")
        
        if choice == "1":
            title = input("Enter task title: ")
            priority = int(input("Enter priority (0-5): "))
            deadline = input("Enter deadline (YYYY-MM-DD) or leave blank: ")
            tags = input("Enter tags (comma-separated): ").split(',') if input else []
            manager.create_task(title, priority, deadline, tags)
        elif choice == "2":
            print(manager.get_all_tasks())
        elif choice == "3":
            task_id = int(input("Enter task ID: "))
            print(manager.get_task_by_id(task_id))
        elif choice == "4":
            task_id = int(input("Enter task ID to update: "))
            new_title = input("New title: ")
            new_priority = int(input("New priority (0-5): "))
            manager.update_task(task_id, title=new_title, priority=new_priority)
        elif choice == "5":
            task_id = int(input("Enter task ID to delete: "))
            manager.delete_task(task_id)
        elif choice == "6":
            tag_name = input("Enter tag name: ")
            print(manager.filter_tasks_by_tag(tag_name))
        elif choice == "7":
            print(manager.get_high_priority_tasks())
        elif choice == "8":
            print(manager.get_overdue_tasks())
        elif choice == "9":
            break
        else:
            print("Invalid choice. Please try again.")