import { Global, Module } from '@nestjs/common';
import { StorageService } from './storage.service';
import { LocalStorageService } from './local-storage.service';
import { PrivateDocumentStorage } from './private-document.storage';

/**
 * Binds {@link StorageService} to the local-disk adapter.
 *
 * @Global so any module can inject StorageService without importing
 * this module explicitly (same pattern as MailerModule / PermissionsModule).
 */
@Global()
@Module({
  providers: [
    { provide: StorageService, useClass: LocalStorageService },
    // Constructor takes an optional test-only path (`string`). Nest would
    // otherwise try to inject a String token. Factory keeps production
    // on cwd/privateUploads.
    { provide: PrivateDocumentStorage, useFactory: () => new PrivateDocumentStorage() },
  ],
  exports: [StorageService, PrivateDocumentStorage],
})
export class StorageModule {}
