// src/storage/storage-location-manager.ts
import { join as join2, isAbsolute as isAbsolute2 } from "path";

// src/storage/fs-storage-backend.ts
import { existsSync, mkdirSync, accessSync, constants } from "fs";
import { join, resolve, isAbsolute } from "path";
var FsStorageBackend = class {
  type = "local";
  basePath;
  constructor(basePath) {
    this.basePath = resolve(basePath);
  }
  resolve(subpath) {
    if (isAbsolute(subpath)) return subpath;
    return join(this.basePath, subpath);
  }
  isAvailable() {
    try {
      if (!existsSync(this.basePath)) return false;
      accessSync(this.basePath, constants.W_OK);
      return true;
    } catch {
      return false;
    }
  }
  async initialize() {
    mkdirSync(this.basePath, { recursive: true });
  }
};

// src/storage/storage-location-manager.ts
var StorageLocationManager = class {
  backends = /* @__PURE__ */ new Map();
  dataPath;
  constructor(dataPath) {
    this.dataPath = dataPath;
  }
  /** Initialize all locations with default paths */
  async initializeDefaults() {
    const defaults = {
      data: join2(this.dataPath, "db"),
      media: join2(this.dataPath, "media"),
      recordings: join2(this.dataPath, "recordings"),
      models: join2(this.dataPath, "models"),
      cache: "/tmp/camstack-cache",
      logs: join2(this.dataPath, "logs")
    };
    for (const [name, path] of Object.entries(defaults)) {
      const backend = new FsStorageBackend(path);
      await backend.initialize();
      this.backends.set(name, backend);
    }
  }
  /** Override a specific location's backend path */
  async setLocationPath(name, basePath) {
    const resolved = isAbsolute2(basePath) ? basePath : join2(this.dataPath, basePath);
    const backend = new FsStorageBackend(resolved);
    await backend.initialize();
    this.backends.set(name, backend);
  }
  /** Get the backend for a location */
  getBackend(name) {
    const backend = this.backends.get(name);
    if (!backend) throw new Error(`Storage location "${name}" not initialized`);
    return backend;
  }
  /** Resolve a path within a location */
  resolve(location, subpath) {
    return this.getBackend(location).resolve(subpath);
  }
  /** Check if all locations are available */
  getStatus() {
    return Array.from(this.backends.entries()).map(([name, backend]) => ({
      name,
      available: backend.isAvailable(),
      path: backend.basePath
    }));
  }
  /** All location names */
  getLocationNames() {
    return Array.from(this.backends.keys());
  }
};

export {
  FsStorageBackend,
  StorageLocationManager
};
//# sourceMappingURL=chunk-2F3XZYRW.mjs.map