/**
 * License ORM Mapper
 *
 * Maps between License domain entity and LicenseOrmEntity
 */

import { License } from '@domain/entities/license.entity';
import { LicenseOrmEntity } from '../entities/license.orm-entity';

export class LicenseOrmMapper {
  /**
   * Map domain entity to ORM entity
   */
  static toOrm(domain: License): LicenseOrmEntity {
    const orm = new LicenseOrmEntity();
    const props = domain.toObject();

    orm.id = props.id;
    orm.subscriptionId = props.subscriptionId;
    orm.userId = props.userId;
    orm.status = props.status;
    orm.assignedAt = props.assignedAt;
    orm.revokedAt = props.revokedAt;

    return orm;
  }

  /**
   * Map ORM entity to domain entity
   */
  static toDomain(orm: LicenseOrmEntity): License {
    return License.fromPersistence({
      id: orm.id,
      subscriptionId: orm.subscriptionId,
      userId: orm.userId,
      status: orm.status,
      assignedAt: orm.assignedAt,
      revokedAt: orm.revokedAt,
    });
  }

  /**
   * Map array of ORM entities to domain entities
   */
  static toDomainMany(orms: LicenseOrmEntity[]): License[] {
    return orms.map(orm => this.toDomain(orm));
  }
}
