import { EntitySchema } from '@mikro-orm/core';
import { v4 as uuidv4 } from 'uuid';
import { BaseEntity } from '../../core/entities/base.entity';

export class Guest extends BaseEntity {
  name!: string;
  email?: string;
  phone?: string;
  rsvp: boolean = false;
  tableId?: string;
}

export const GuestSchema = new EntitySchema<Guest>({
  class: Guest,
  tableName: 'guests',
  properties: {
    id: {
      type: 'uuid',
      primary: true,
      default: uuidv4(),
    },
    tenantId: {
      type: 'string',
    },
    metadata: {
      type: 'json',
      nullable: true,
    },
    createdAt: {
      type: 'date',
      default: new Date(),
    },
    updatedAt: {
      type: 'date',
      default: new Date(),
    },
    name: {
      type: 'string',
    },
    email: {
      type: 'string',
      nullable: true,
    },
    phone: {
      type: 'string',
      nullable: true,
    },
    rsvp: {
      type: 'boolean',
      default: false,
    },
    tableId: {
      type: 'uuid',
      nullable: true,
    },
  },
});

export class GuestNotificationPreference extends BaseEntity {
  guestId!: string;
  email: boolean = true;
  whatsapp: boolean = false;
  metadata?: Record<string, any>;
}

export const GuestNotificationPreferenceSchema = new EntitySchema<GuestNotificationPreference>({
  class: GuestNotificationPreference,
  tableName: 'guest_notification_preferences',
  properties: {
    id: {
      type: 'uuid',
      primary: true,
      default: uuidv4(),
    },
    tenantId: {
      type: 'string',
    },
    metadata: {
      type: 'json',
      nullable: true,
    },
    createdAt: {
      type: 'date',
      default: new Date(),
    },
    updatedAt: {
      type: 'date',
      default: new Date(),
    },
    guestId: {
      type: 'uuid',
    },
    email: {
      type: 'boolean',
      default: true,
    },
    whatsapp: {
      type: 'boolean',
      default: false,
    },
  },
});
