import 'package:drift/drift.dart';

import '../facade/storage_sdk_api.dart';
import '../../data/local/datasources/database_datasource.dart';
import '../../data/repositories/database_repository_impl.dart';
import 'storage_sdk_core.dart';
import 'storage_sdk_api_impl.dart';

/// SDK 依赖装配入口。
///
/// 调用方传入数据库工厂和表注册表，SDK 负责连接生命周期和 CRUD 机制。
///
/// 示例（im_app 的 DI 层）：
/// ```dart
/// StorageSdkWiring.build(
///   databaseFactory: (executor) => AppDatabase(executor),
///   tableRegistry: (db) => {
///     User: (db as AppDatabase).users,
///   },
/// );
/// ```
class StorageSdkWiring {
  StorageSdkWiring._();

  static StorageSdkApi build({
    required GeneratedDatabase Function(QueryExecutor) databaseFactory,
    required Map<Type, TableInfo> Function(GeneratedDatabase) tableRegistry,
  }) {
    final dataSource = DatabaseDataSource(databaseFactory: databaseFactory);
    final repo = DatabaseRepositoryImpl(dataSource);
    final core = StorageSdkCore(dataSource: dataSource, repo: repo);
    return StorageSdkApiImpl(core: core, tableRegistry: tableRegistry);
  }
}