import {
  Notification,
  NotificationType,
  NotificationPriority,
} from '@domain/entities/notification.entity';
import { NotificationOrmEntity } from '../entities/notification.orm-entity';

/**
 * Notification Mapper
 *
 * Maps between domain Notification entity and ORM entity
 */
export class NotificationMapper {
  /**
   * Map ORM entity to domain entity
   */
  static toDomain(ormEntity: NotificationOrmEntity): Notification {
    return Notification.fromPersistence({
      id: ormEntity.id,
      userId: ormEntity.user_id,
      organizationId: ormEntity.organization_id,
      type: ormEntity.type as NotificationType,
      priority: ormEntity.priority as NotificationPriority,
      title: ormEntity.title,
      message: ormEntity.message,
      metadata: ormEntity.metadata,
      read: ormEntity.read,
      readAt: ormEntity.read_at,
      actionUrl: ormEntity.action_url,
      createdAt: ormEntity.created_at,
    });
  }

  /**
   * Map domain entity to ORM entity (for creation)
   */
  static toOrmCreate(domain: Notification): Partial<NotificationOrmEntity> {
    return {
      id: domain.id,
      user_id: domain.userId,
      organization_id: domain.organizationId,
      type: domain.type,
      priority: domain.priority,
      title: domain.title,
      message: domain.message,
      metadata: domain.metadata,
      read: domain.read,
      read_at: domain.readAt,
      action_url: domain.actionUrl,
      created_at: domain.createdAt,
    };
  }

  /**
   * Map domain entity to ORM entity (for update)
   */
  static toOrmUpdate(domain: Notification): Partial<NotificationOrmEntity> {
    return {
      read: domain.read,
      read_at: domain.readAt,
    };
  }

  /**
   * Map array of ORM entities to domain entities
   */
  static toDomainArray(ormEntities: NotificationOrmEntity[]): Notification[] {
    return ormEntities.map(entity => this.toDomain(entity));
  }
}
