export class ResourceService {
    db;
    constructor(db) {
        this.db = db;
    }
    addResource(topicId, title, url, source = 'manual') {
        const result = this.db.raw.prepare('INSERT INTO resources (topic_id, title, url, source) VALUES (?, ?, ?, ?)').run(topicId, title, url, source);
        return this.db.raw.prepare('SELECT * FROM resources WHERE id = ?').get(result.lastInsertRowid);
    }
    listForTopic(topicId) {
        return this.db.raw.prepare('SELECT * FROM resources WHERE topic_id = ? ORDER BY created_at ASC, id ASC').all(topicId);
    }
    importResources(resources) {
        const insert = this.db.raw.prepare('INSERT INTO resources (topic_id, title, url, source) VALUES (?, ?, ?, ?)');
        const tx = this.db.raw.transaction((items) => {
            for (const r of items) {
                insert.run(r.topic_id, r.title, r.url, 'import');
            }
            return items.length;
        });
        return tx(resources);
    }
    deleteResource(id) {
        this.db.raw.prepare('DELETE FROM resources WHERE id = ?').run(id);
    }
}
//# sourceMappingURL=resources.js.map