const db = require('../config/db');

async function getLocalDBVersion() {
  const [rows] = await db.execute(
    'SELECT database_version, last_update FROM db_version ORDER BY last_update DESC LIMIT 1'
  );
  return rows.length ? rows[0] : null;
}

async function setLocalDBVersion(version, date) {
  await db.execute(
    'INSERT INTO db_version (database_version, last_update) VALUES (?, ?)',
    [version ?? null, date ?? null]
  );
}

module.exports = { getLocalDBVersion, setLocalDBVersion };