import { AbstractDtoEntityMapper } from "./AbstractDtoEntityMapper.js";
import { UserEntity } from "../entities/UserEntity.js";
import { UserDto } from "../dtos/UserDto.js";
import { ValidationError } from "../errors/httpErrors.js";

export class UserDtoEntityMapper extends AbstractDtoEntityMapper<UserEntity, UserDto> {
  toDto(entity: UserEntity): UserDto {
    const dto = new UserDto();
    this.mapBaseEntityToDto(entity, dto);

    dto.userName = entity.userName;
    dto.email = entity.email;
    dto.firstName = entity.firstName;
    dto.lastName = entity.lastName;
    dto.role = entity.role;

    return dto;
  }

  toEntity(dto: UserDto): UserEntity {
    const entity = new UserEntity();
    this.mapBaseDtoToEntity(dto, entity);

    entity.userName = dto.userName;
    entity.email = dto.email;
    entity.firstName = dto.firstName;
    entity.lastName = dto.lastName;
    if(dto.role){
      entity.role = dto.role;
    }

    return entity;
  }
}
