import * as path from 'path';
import * as fs from 'fs';
import { resolveDataDir } from './data-dir';

export const pDataPath = () => {
  const dirPath = resolveDataDir();
  if (!fs.existsSync(dirPath)) fs.mkdirSync(dirPath, { recursive: true });
  return dirPath;
};

export const pUploadPath = () => {
  const uploadPath = path.join(pDataPath(), 'uploads');
  if (!fs.existsSync(uploadPath)) fs.mkdirSync(uploadPath, { recursive: true });
  return uploadPath;
};

export const pWorkspacePath = () => {
  const workspacePath = path.join(pDataPath(), 'workspace');
  if (!fs.existsSync(workspacePath)) fs.mkdirSync(workspacePath, { recursive: true });
  return workspacePath;
};

export const pPluginPath = () => {
  const pluginPath = path.join(pDataPath(), 'plugins');
  if (!fs.existsSync(pluginPath)) fs.mkdirSync(pluginPath, { recursive: true });
  return pluginPath;
};

export const pSqlitePath = () => path.join(pDataPath(), 'cool.sqlite');

export const pCachePath = () => {
  const cachePath = path.join(pDataPath(), 'cache');
  if (!fs.existsSync(cachePath)) fs.mkdirSync(cachePath, { recursive: true });
  return cachePath;
};
