"""
Knowledge Organizer
Generated by Eden via recursive self-improvement
2025-10-27 21:35:18.959267
"""

class Note:
    """Represents a single note that can be added to categories."""
    
    def __init__(self, title, content):
        self.title = title
        self.content = content
        
    def get_title(self):
        return self.title
    
    def get_content(self):
        return self.content
    
    def set_title(self, new_title):
        self.title = new_title
        
    def set_content(self, new_content):
        self.content = new_content


class Category:
    """Represents a category to organize notes."""
    
    def __init__(self, name):
        self.name = name
        self.notes = []
        
    def add_note(self, note):
        """Add a note to this category."""
        if isinstance(note, Note):
            self.notes.append(note)
        else:
            raise ValueError("Note must be an instance of Note class")
    
    def remove_note(self, title):
        """Remove a note with the given title from this category."""
        for note in self.notes:
            if note.get_title() == title:
                self.notes.remove(note)
                return True
        return False
    
    def search_notes(self, keyword):
        """Search notes in this category for a keyword."""
        found_notes = []
        for note in self.notes:
            if keyword.lower() in note.get_title().lower() or \
               keyword.lower() in note.get_content().lower():
                found_notes.append(note)
        return found_notes
    
    def get_all_notes(self):
        """Return all notes in this category."""
        return self.notes.copy()
    
    def get_category_name(self):
        """Return the name of this category."""
        return self.name


class KnowledgeOrganizer:
    """Manages multiple categories and their associated notes."""
    
    def __init__(self):
        self.categories = {}
        
    def create_category(self, category_name):
        """Create a new category with the given name."""
        if not isinstance(category_name, str) or len(category_name.strip()) == 0:
            raise ValueError("Category name must be a non-empty string.")
        if category_name in self.categories:
            raise Exception(f"Category '{category_name}' already exists.")
        self.categories[category_name] = Category(category_name)
    
    def delete_category(self, category_name):
        """Delete an existing category."""
        if category_name not in self.categories:
            raise Exception(f"Category '{category_name}' does not exist.")
        del self.categories[category_name]
        
    def add_note_to_category(self, category_name, note):
        """Add a note to the specified category."""
        if category_name not in self.categories:
            raise Exception(f"Category '{category_name}' does not exist.")
        if not isinstance(note, Note):
            raise ValueError("Note must be an instance of Note class")
        self.categories[category_name].add_note(note)
    
    def search_notes_by_keyword(self, keyword):
        """Search all notes across categories for a keyword."""
        found_notes = []
        for category in self.categories.values():
            found_notes.extend(category.search_notes(keyword))
        return found_notes
    
    def get_all_categories_names(self):
        """Return the names of all available categories."""
        return list(self.categories.keys())
    
    def get_notes_in_category(self, category_name):
        """Get all notes from a specific category."""
        if category_name not in self.categories:
            raise Exception(f"Category '{category_name}' does not exist.")
        return self.categories[category_name].get_all_notes()
    
    def delete_note_from_category(self, category_name, title):
        """Delete a note with the given title from a specific category."""
        if category_name not in self.categories:
            raise Exception(f"Category '{category_name}' does not exist.")
        if not isinstance(title, str) or len(title.strip()) == 0:
            raise ValueError("Note title must be a non-empty string.")
        return self.categories[category_name].remove_note(title)
# Example usage of the Knowledge Organizer capability

from datetime import datetime

# Initialize knowledge organizer
knowledge = KnowledgeOrganizer()

# Create categories
knowledge.create_category("Personal")
knowledge.create_category("Work")

# Add notes to categories
personal_cat = knowledge.categories["Personal"]
work_cat = knowledge.categories["Work"]

note1 = Note("Meeting Notes", "Discuss project timeline and deliverables.")
personal_cat.add_note(note1)

note2 = Note("Task Completion", "Review the Q3 report by EOD.")
work_cat.add_note(note2)

# Search across all categories
results = knowledge.search_notes_by_keyword("report")
print(f"Found notes: {[note.get_title() for note in results]}")

# Get specific category's notes
personal_notes = knowledge.get_notes_in_category("Personal")
print(f"\nPersonal notes count: {len(personal_notes)}")

# Delete a note
success = knowledge.delete_note_from_category("Work", "Task Completion")
if success:
    print("\nNote deleted successfully.")

# Remove a category
knowledge.delete_category("Personal")