const path = require('path');

function resolvePath(root, value, fallback) {
  if (!value) return fallback;
  if (path.isAbsolute(value)) return value;
  return path.join(root, value);
}

const DATA_ROOT = process.env.CHAT_DATA_ROOT || path.join(process.cwd(), '.data');
const STATE_DIR = path.join(DATA_ROOT, '.opencode-chat');
const DEFAULT_DB_PATH = path.join(DATA_ROOT, '.data', 'shopify_ai.db');
const DB_PATH = resolvePath(DATA_ROOT, process.env.DATABASE_PATH, DEFAULT_DB_PATH);
const DEFAULT_KEY_FILE = path.join(path.dirname(DB_PATH), '.encryption_key');
const KEY_FILE = resolvePath(DATA_ROOT, process.env.DATABASE_KEY_FILE, DEFAULT_KEY_FILE);

module.exports = {
  DATA_ROOT,
  STATE_DIR,
  DB_PATH,
  KEY_FILE
};
