import { EventType } from '@mikro-orm/core';
import { getMetadataFromDecorator } from '../utils.js';
function hook(type) {
  return function (target, method) {
    const meta = getMetadataFromDecorator(target.constructor);
    meta.hooks[type] ??= [];
    meta.hooks[type].push(method);
  };
}
/** Called before a new entity is persisted to the database (legacy TypeScript decorator). */
export function BeforeCreate() {
  return hook(EventType.beforeCreate);
}
/** Called after a new entity has been persisted to the database (legacy TypeScript decorator). */
export function AfterCreate() {
  return hook(EventType.afterCreate);
}
/** Called before an existing entity is updated in the database (legacy TypeScript decorator). */
export function BeforeUpdate() {
  return hook(EventType.beforeUpdate);
}
/** Called after an existing entity has been updated in the database (legacy TypeScript decorator). */
export function AfterUpdate() {
  return hook(EventType.afterUpdate);
}
/** Called before an entity is upserted (legacy TypeScript decorator). */
export function BeforeUpsert() {
  return hook(EventType.beforeUpsert);
}
/** Called after an entity has been upserted (legacy TypeScript decorator). */
export function AfterUpsert() {
  return hook(EventType.afterUpsert);
}
/** Called when an entity is instantiated by the EntityManager (legacy TypeScript decorator). */
export function OnInit() {
  return hook(EventType.onInit);
}
/** Called after an entity is loaded from the database (legacy TypeScript decorator). */
export function OnLoad() {
  return hook(EventType.onLoad);
}
/**
 * Called before deleting entity, but only when providing initialized entity to EM#remove()
 */
export function BeforeDelete() {
  return hook(EventType.beforeDelete);
}
/**
 * Called after deleting entity, but only when providing initialized entity to EM#remove()
 */
export function AfterDelete() {
  return hook(EventType.afterDelete);
}
