package ru.kayashov.bar.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import ru.kayashov.bar.controller.dto.cocktail.ReceiptResponseDto;
import ru.kayashov.bar.controller.dto.ingredient.IngredientSimpleResponseDto;
import ru.kayashov.bar.model.entity.CocktailEntity;
import ru.kayashov.bar.repository.CocktailRepository;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class ReceiptService {

    private final CocktailRepository cocktailRepository;

    public List<ReceiptResponseDto> getReceiptList(Long cocktailId) {
        CocktailEntity cocktail = cocktailRepository.findById(cocktailId).orElseThrow();
        return cocktail.getReceipt().stream()
                .map(e -> ReceiptResponseDto.builder()
                        .id(e.getId())
                        .ingredient(IngredientSimpleResponseDto.mapToDto(e.getIngredient()))
                        .measure(e.getMeasure())
                        .build())
                .toList();
    }
}
