import { RecipeIngredientDto } from "../api/dtos/RecipeIngredientDto.js";
import { RecipeIngredientEntity } from "../entities/RecipeIngredientEntity.js";
import { AbstractDtoEntityMapper } from "./AbstractDtoEntityMapper.js";

export class RecipeIngredientDtoEntityMapper extends AbstractDtoEntityMapper<RecipeIngredientEntity, RecipeIngredientDto>{
    
    toDto(entity: RecipeIngredientEntity): RecipeIngredientDto {
        const dto = new RecipeIngredientDto();
        this.mapBaseEntityToDto(entity, dto);

        dto.amount = entity.amount;
        dto.name = entity.name;
        dto.unit = entity.unit;
        dto.sortOrder = entity.sortOrder;
        dto.subtext = entity.subtext;

        return dto;
    }

    toEntity(dto: RecipeIngredientDto): RecipeIngredientEntity {
        const entity = new RecipeIngredientEntity();
        this.mapBaseDtoToEntity(dto,entity);

        entity.amount = dto.amount;
        entity.name = dto.name;
        entity.unit = dto.unit;
        entity.sortOrder = dto.sortOrder;
        entity.subtext = dto.subtext;

        return entity;
    }

    createNewEntity(): RecipeIngredientEntity {
        return new RecipeIngredientEntity();
    }

    mergeDtoIntoEntity(dto: RecipeIngredientDto, entity: RecipeIngredientEntity): RecipeIngredientEntity {
        entity.name = dto.name;
        entity.amount = dto.amount;
        entity.unit = dto.unit;
        entity.subtext = dto.subtext;
        entity.sortOrder = dto.sortOrder;
        return entity;
    }
}