import 'package:drift/drift.dart';
import 'package:sendtrain/database/database.dart';

part 'activity_actions_dao.g.dart';

@DriftAccessor(tables: [ActivityActions])
class ActivityActionsDao extends DatabaseAccessor<AppDatabase> with _$ActivityActionsDaoMixin {
  ActivityActionsDao(super.db);

  Future<List<ActivityAction>> all() => select(activityActions).get();
  Stream<List<ActivityAction>> watch() => select(activityActions).watch();
  Future insert(ActivityAction activityAction) => into(activityActions).insert(activityAction);
  Future replace(ActivityAction activityAction) => update(activityActions).replace(activityAction);
  Future remove(ActivityAction activityAction) => delete(activityActions).delete(activityAction);
  Future createOrUpdate(ActivityActionsCompanion activityAction) => into(activityActions).insertOnConflictUpdate(activityAction);

  // Future<List<ActivityAction>> all() async {
  //   return await select(activityActions).get();
  // }

  Future<ActivityAction> find(int id) async {
    return await (select(activityActions)..where((activityAction) => activityAction.id.equals(id) )).getSingle();
  }

  Future<List<ActivityAction>> fromActivityId(int id) async {
    final result = db.managers.activityActions
        .filter((activityAction) => activityAction.activityId.id(id));

    return result.get();
  }
}