import { EventType } from '@mikro-orm/core';
function hook(type) {
  return function (value, context) {
    const meta = context.metadata;
    meta.hooks ??= {};
    meta.hooks[type] ??= [];
    meta.hooks[type].push(value);
  };
}
/** Called before a new entity is persisted to the database (TC39 decorator). */
export function BeforeCreate() {
  return hook(EventType.beforeCreate);
}
/** Called after a new entity has been persisted to the database (TC39 decorator). */
export function AfterCreate() {
  return hook(EventType.afterCreate);
}
/** Called before an existing entity is updated in the database (TC39 decorator). */
export function BeforeUpdate() {
  return hook(EventType.beforeUpdate);
}
/** Called after an existing entity has been updated in the database (TC39 decorator). */
export function AfterUpdate() {
  return hook(EventType.afterUpdate);
}
/** Called before an entity is upserted (TC39 decorator). */
export function BeforeUpsert() {
  return hook(EventType.beforeUpsert);
}
/** Called after an entity has been upserted (TC39 decorator). */
export function AfterUpsert() {
  return hook(EventType.afterUpsert);
}
/** Called when an entity is instantiated by the EntityManager (TC39 decorator). */
export function OnInit() {
  return hook(EventType.onInit);
}
/** Called after an entity is loaded from the database (TC39 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);
}
