import { EntitySchema } from '@mikro-orm/core';
import { BaseEntity } from './base.entity';

export class NotificationRule extends BaseEntity {
  module!: string; // e.g. 'guest', 'gift', 'todo'

  event!: string; // e.g. 'guest.invited', 'todo.completed'

  channels!: Array<'email' | 'whatsapp' | 'sms' | 'custom'>;

  conditions?: Record<string, any>;
}

export const NotificationRuleSchema = new EntitySchema<NotificationRule>({
  class: NotificationRule,
  tableName: 'notification_rules',
  properties: {
    id: { primary: true, type: 'uuid', defaultRaw: 'uuid_generate_v4()' },
    tenantId: { type: 'string' },
    metadata: { type: 'json', nullable: true },
    createdAt: { type: 'date', defaultRaw: 'now()' },
    updatedAt: { type: 'date', defaultRaw: 'now()' },

    module: { type: 'string' },
    event: { type: 'string' },
    channels: { type: 'json' },
    conditions: { type: 'json', nullable: true },
  },
});
