
import Database from 'better-sqlite3';
import path from 'path';

const dbPath = path.join(process.cwd(), 'media.db');
const db = new Database(dbPath);

db.exec(`
  CREATE TABLE IF NOT EXISTS libraries (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    path TEXT NOT NULL UNIQUE
  );
`);

db.exec(`
  CREATE TABLE IF NOT EXISTS media (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    library_id INTEGER,
    path TEXT NOT NULL UNIQUE,
    type TEXT NOT NULL,
    title TEXT,
    size INTEGER,
    thumbnail TEXT,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (library_id) REFERENCES libraries (id)
  );
`);

export default db;
