package ru.kayashov.bar.controller.dto.cocktail;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import ru.kayashov.bar.model.entity.CocktailEntity;

import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CocktailForListResponseDto {
    private Long id;
    private String name;
    private String image;
    private String video;
    private String instructions;
    private Boolean inMenu;

    private String category;
    private String alcoholic;
    private String glass;

    private Integer volume;
    private Boolean hasError;

    private String tags;
    private String components;
    private Boolean isAllowed;

    private List<ReceiptResponseDto> receipt;

    private RatingResponseDto rating;

    public static CocktailForListResponseDto mapToDto(CocktailEntity e, Long visitorId) {
        CocktailForListResponseDto d = new CocktailForListResponseDto();
        d.setId(e.getId());
        d.setName(e.getName());
        d.setImage(e.getImage());
        d.setVideo(e.getVideo());
        d.setInstructions(e.getInstructions());

        d.setCategory(e.getCategory().getName());
        d.setAlcoholic(e.getAlcoholic().getValue());
        d.setGlass(e.getGlass().getName());

        String components = e.getReceipt().stream().map(r -> r.getIngredient().getName()).collect(Collectors.joining(", "));
        d.setComponents(components);
        d.setReceipt(e.getReceipt().stream().map(ReceiptResponseDto::mapToDto).toList());

        RatingResponseDto rating = new RatingResponseDto();
        rating.setFavourite(e.getIsFavorite());
        rating.setRating(e.getRating());
        d.setRating(rating);
        return d;
    }
}
