import 'package:sqflite/sqflite.dart';

import 'repository.dart';
import 'sqlite_repository.dart';

abstract class RepositoryFactory {
  Repository<T> getRepository<T>({
    required String tableName,
    required T Function(Map<String, dynamic>) fromMap,
    required Map<String, dynamic> Function(T) toMap,
  });
}

class SQLiteRepositoryFactory implements RepositoryFactory {
  final Database database;

  SQLiteRepositoryFactory(this.database);

  @override
  Repository<T> getRepository<T>({
    required String tableName,
    required T Function(Map<String, dynamic>) fromMap,
    required Map<String, dynamic> Function(T) toMap,
  }) {
    return SQLiteRepository<T>(
      database: database,
      tableName: tableName,
      fromMap: fromMap,
      toMap: toMap,
    );
  }
}
