"""
NoteManager
Generated by Eden via recursive self-improvement
2025-10-27 20:01:24.409091
"""

class NoteManager:
    """
    Manages a collection of notes with categorization, tagging, and search functionality.
    
    Attributes:
        storage (dict): Dictionary to store notes. Keys are note IDs, values are note objects.
        
    Methods:
        create_note: Creates a new note with title, content, category, tags, and importance level.
        get_notes_by_category: Retrieves notes filtered by category.
        get_notes_by_tag: Retrieves notes filtered by tag.
        update_note: Updates an existing note's attributes.
        delete_note: Removes a note from storage.
    """
    
    def __init__(self):
        self.storage = {}
        
    def create_note(self, title, content, category, tags=None, importance="medium"):
        """
        Creates and stores a new note with given attributes.
        
        Args:
            title (str): Note title
            content (str): Main content of the note
            category (str): Category for organization
            tags (list): List of relevant tags. Defaults to None.
            importance (str): Importance level ("low", "medium", "high"). Defaults to "medium".
        """
        if tags is None:
            tags = []
            
        note_id = len(self.storage) + 1
        self.storage[note_id] = {
            "title": title,
            "content": content,
            "category": category,
            "tags": tags,
            "importance": importance
        }
        
    def get_notes_by_category(self, category):
        """
        Retrieves notes filtered by category.
        
        Args:
            category (str): Category to filter by
        
        Returns:
            list: List of notes in the specified category
        """
        return [note for note_id, note in self.storage.items() if note["category"] == category]
    
    def get_notes_by_tag(self, tag):
        """
        Retrieves notes filtered by tag.
        
        Args:
            tag (str): Tag to filter by
        
        Returns:
            list: List of notes with the specified tag
        """
        return [note for note_id, note in self.storage.items() if tag in note["tags"]]
    
    def update_note(self, note_id, **kwargs):
        """
        Updates attributes of an existing note.
        
        Args:
            note_id (int): ID of the note to update
            kwargs: Dictionary of attributes to update and their new values
        """
        if note_id in self.storage:
            note = self.storage[note_id]
            for key, value in kwargs.items():
                if key in note:
                    note[key] = value
    
    def delete_note(self, note_id):
        """
        Deletes a note from storage.
        
        Args:
            note_id (int): ID of the note to delete
        """
        if note_id in self.storage:
            del self.storage[note_id]

# Example usage:
if __name__ == "__main__":
    manager = NoteManager()
    
    # Create notes
    manager.create_note("Python Tips", "Use f-strings for string formatting.", "Programming", ["python", "tips"], importance="high")
    manager.create_note("ML Basics", "Understand the difference between supervised and unsupervised learning.", "Machine Learning", ["ml", "basics"])
    
    # Retrieve notes by category
    programming_notes = manager.get_notes_by_category("Programming")
    print("\nNotes in Programming:")
    for note in programming_notes:
        print(f"Title: {note['title']}")
        print(f"Content: {note['content']}\n")
    
    # Retrieve notes by tag
    ml_notes = manager.get_notes_by_tag("ml")
    print("\nNotes tagged with ML:")
    for note in ml_notes:
        print(f"Title: {note['title']}")
        print(f"Content: {note['content']}\n")
    
    # Update a note
    manager.update_note(1, content="Use formatted strings with {} syntax.", importance="medium")
    
    # Delete a note
    manager.delete_note(2)