import { AbstractDto } from "../dtos/AbstractDto.js";
import { AbstractEntity } from "../entities/AbstractEntity.js";

export abstract class AbstractDtoEntityMapper<
  E extends AbstractEntity,
  D extends AbstractDto
> {
  /**
   * Map base entity fields (id, createdAt, updatedAt) to DTO.
   */
  protected mapBaseEntityToDto(entity: E, dto: D): D {
    dto.id = entity.id;
    dto.createdAt = entity.createdAt;
    dto.updatedAt = entity.updatedAt;
    return dto;
  }

  /**
   * Map base DTO fields to entity.
   */
  protected mapBaseDtoToEntity(dto: D, entity: E): E {
    entity.id = dto.id;
    entity.createdAt = dto.createdAt;
    entity.updatedAt = dto.updatedAt;
    return entity;
  }

  // Abstract methods to be implemented by subclasses
  abstract toDto(entity: E): D;
  abstract toEntity(dto: D): E;
}
