import { AbstractDtoEntityMapper } from "./AbstractDtoEntityMapper.js";
import { TagEntity } from "../entities/TagEntity.js";
import { TagDto } from "../api/dtos/TagDto.js";

/**
 * Maps between TagDto (API layer) and TagEntity (persistence layer).
 */
export class TagDtoEntityMapper extends AbstractDtoEntityMapper<TagEntity, TagDto> {

    /**
     * Maps a TagEntity to a TagDto for outbound API responses.
     */
    toDto(entity: TagEntity): TagDto {
        const dto = new TagDto();
        this.mapBaseEntityToDto(entity, dto);
        dto.description = entity.description;
        return dto;
    }

    /**
     * Maps a TagDto to a new TagEntity.
     */
    toEntity(dto: TagDto): TagEntity {
        const entity = this.createNewEntity();
        return this.mergeDtoIntoEntity(dto, entity);
    }

    /**
     * Merges changes from a TagDto into an existing TagEntity.
     * Used when updating a tag.
     */
    mergeDtoIntoEntity(dto: TagDto, entity: TagEntity): TagEntity {
        this.mapBaseDtoToEntity(dto, entity);
        entity.description = dto.description;
        return entity;
    }

    /**
     * Creates a blank TagEntity. Required by mergeDtoListIntoEntityList.
     */
    createNewEntity(): TagEntity {
        return new TagEntity();
    }
}