import { Sequelize, Transaction } from "sequelize";
import { TransactionManager } from "../database";

export class SequelizeTransactionManager extends TransactionManager {
  protected _database: any | null = null;

  protected async _startTransaction(): Promise<Transaction> {
    return await this._database.transaction();
  }

  protected async _commitTransaction(): Promise<void> {
    if (this._transaction) {
      await this._transaction.commit();
    }
  }

  protected async _rollbackTransaction(): Promise<void> {
    if (this._transaction) {
      await this._transaction.rollback();
    }
  }

  constructor(database: Sequelize) {
    super();
    this._database = database;
  }
}
