const fs = require('fs');
const os = require('os');
const path = require('path');

function ensureDir(dirPath) {
  if (!fs.existsSync(dirPath)) {
    fs.mkdirSync(dirPath, { recursive: true });
  }
  return dirPath;
}

function getDefaultDataDir() {
  return path.join(os.homedir(), '.org-board-ai');
}

function getDataDir() {
  return ensureDir(process.env.ORG_BOARD_DATA_DIR || getDefaultDataDir());
}

function getDbPath() {
  const targetPath = process.env.ORG_BOARD_DB_PATH || path.join(getDataDir(), 'org-board.db');
  ensureDir(path.dirname(targetPath));
  return targetPath;
}

module.exports = {
  ensureDir,
  getDataDir,
  getDbPath
};
