package com.bares.service.mapper;

import com.bares.domain.*;
import com.bares.service.dto.ProductoDTO;

import org.mapstruct.*;

/**
 * Mapper for the entity Producto and its DTO ProductoDTO.
 */
@Mapper(componentModel = "spring", uses = {CategoriaMapper.class, BarMapper.class})
public interface ProductoMapper extends EntityMapper<ProductoDTO, Producto> {

    @Mapping(source = "tipo.id", target = "tipoId")
    @Mapping(source = "tipo.nombre", target = "tipoNombre")
    @Mapping(source = "bar.id", target = "barId")
    @Mapping(source = "bar.nombre", target = "barNombre")
    ProductoDTO toDto(Producto producto);

    @Mapping(source = "tipoId", target = "tipo")
    @Mapping(source = "barId", target = "bar")
    Producto toEntity(ProductoDTO productoDTO);

    default Producto fromId(Long id) {
        if (id == null) {
            return null;
        }
        Producto producto = new Producto();
        producto.setId(id);
        return producto;
    }
}
