# Feature: Tagging

This document outlines the implementation of a tagging feature for Bibliotheca.

## 1. Database Schema

The database schema will be updated to support tags.

- A `tags` table will be created to store all available tags.
  ```sql
  CREATE TABLE IF NOT EXISTS tags (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL UNIQUE
  );
  ```

- A `book_tags` table will be created to associate tags with books.
  ```sql
  CREATE TABLE IF NOT EXISTS book_tags (
    book_id TEXT NOT NULL,
    tag_id INTEGER NOT NULL,
    FOREIGN KEY (book_id) REFERENCES books(id) ON DELETE CASCADE,
    FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE,
    PRIMARY KEY (book_id, tag_id)
  );
  ```

## 2. Model

- The `Book` class in `Book.hpp` will be extended to include a list of tags.
  ```cpp
  class Book {
    // ... existing members
    std::vector<std::string> m_tags;
  };
  ```

- The `DatabaseManager` will be updated with methods to:
  - `add_tag_to_book(book_id, tag_name)`
  - `remove_tag_from_book(book_id, tag_name)`
  - `get_tags_for_book(book_id)`
  - `load_all_books` will be updated to also load the tags for each book.

## 3. View

- A new `BookDetails` widget will be created. This widget will:
  - Display the book's cover, title, author, and other metadata.
  - Display the tags associated with the book.
  - Provide a way to add new tags to the book.
  - Provide a way to remove existing tags from the book.
  - Have a button to open the book file.

- The `BibliothecaWindow` will be modified to:
  - Show the `BookDetails` widget when a book is activated.
  - The `onBookActivated` method will be updated to show the `BookDetails` widget instead of opening the book file directly.

## 4. User Interaction

- Users will be able to add tags to a book from the `BookDetails` view.
- Users will be able to remove tags from a book from the `BookDetails` view.
- The search functionality will be extended to allow searching for books by tag.
