package ru.kayashov.bar.mapper;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import ru.kayashov.bar.controller.dto.ingredient.IngredientResponseDto;
import ru.kayashov.bar.controller.dto.ingredient.IngredientSimpleResponseDto;
import ru.kayashov.bar.model.entity.IngredientEntity;

import java.util.List;

@Component
@RequiredArgsConstructor
public class IngredientMapper {

    public List<IngredientResponseDto> mapIngredientsToDtoList(List<IngredientEntity> ingredients) {
        return ingredients.stream()
                .map(this::mapIngredientToDto)
                .toList();
    }

    private IngredientResponseDto mapIngredientToDto(IngredientEntity i) {
        return IngredientResponseDto
                .builder()
                .id(i.getId())
                .name(i.getName())
                .alcohol(i.getAlcohol())
                .type(i.getType() != null ? i.getType().getName() : null)
                .abv(i.getAbv())
                .isHave(i.getIsHave())
                .image("https://thecocktaildb.com/images/ingredients/" + i.getEnName() + "-Medium.png")
                .description(i.getDescription())
                .build();
    }

    public List<IngredientSimpleResponseDto> mapIngredientsToSimpleDtoList(List<IngredientEntity> ingredients) {
        return ingredients.stream()
                .map(this::mapIngredientToSimpleDto)
                .toList();
    }

    private IngredientSimpleResponseDto mapIngredientToSimpleDto(IngredientEntity i) {
        return new IngredientSimpleResponseDto(i.getId(), i.getName(),
                "https://thecocktaildb.com/images/ingredients/" + i.getEnName() + "-Medium.png",
                i.getIsHave());
    }
}
