import { db } from '../database.js'

export const settingsRepository = {
  async get(key) {
    const row = await db.selectOne('SELECT value FROM settings WHERE key = ?', [key])
    return row ? row.value : null
  },

  async set(key, value) {
    return db.run('INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)', [key, value])
  },

  async getAll() {
    const rows = await db.selectAll('SELECT key, value FROM settings')
    const map = {}
    for (const row of rows) {
      map[row.key] = row.value
    }
    return map
  },
}
