import { ObjectStorage, StoredObject } from './interface.js';

export class LocalStorageProvider implements ObjectStorage {
  private store = new Map<string, { buffer: Buffer; contentType: string }>();

  async put(key: string, buffer: Buffer, contentType: string): Promise<StoredObject> {
    this.store.set(key, { buffer, contentType });
    return {
      key,
      url: `http://localhost:3000/v1/storage/${key}`,
      sizeBytes: buffer.length,
      expiresAt: new Date(Date.now() + 3600 * 1000).toISOString(),
    };
  }

  async createDownloadUrl(key: string, _expiresInSeconds: number): Promise<string> {
    if (!this.store.has(key)) {
      throw new Error(`File with key '${key}' not found in local storage`);
    }
    return `http://localhost:3000/v1/storage/${key}`;
  }

  async delete(key: string): Promise<void> {
    this.store.delete(key);
  }
}
