package vn.azteam.tpf.service.mapper;

import vn.azteam.tpf.domain.*;
import vn.azteam.tpf.service.dto.TBProductBlockDetailsDTO;

import org.mapstruct.*;

/**
 * Mapper for the entity TBProductBlockDetails and its DTO TBProductBlockDetailsDTO.
 */
@Mapper(componentModel = "spring", uses = {TBProductUnitMapper.class, TBCropMapper.class, TBEntityMapper.class})
public interface TBProductBlockDetailsMapper extends EntityMapper<TBProductBlockDetailsDTO, TBProductBlockDetails> {

    @Mapping(source = "tbEntity.id", target = "tbEntityId")
    @Mapping(source = "tbEntity.name", target = "tbEntityName")
    @Mapping(source = "tbCrop.id", target = "tbCropId")
    @Mapping(source = "tbCrop.code", target = "tbCropCode")
    @Mapping(source = "tbCrop.tbSupplies.name", target = "tbSuppliesName")
    @Mapping(source = "tbProductUnit.id", target = "tbProductUnitId")
    @Mapping(source = "tbProductUnit.name", target = "tbProductUnitName")
    @Mapping(target = "importQuantity", ignore = true)
    @Mapping(target = "description", ignore = true)
    TBProductBlockDetailsDTO toDto(TBProductBlockDetails tBProductBlockDetails);

    @Mapping(source = "tbEntityId", target = "tbEntity")
    @Mapping(source = "tbCropId", target = "tbCrop")
    @Mapping(source = "tbProductUnitId", target = "tbProductUnit")
    TBProductBlockDetails toEntity(TBProductBlockDetailsDTO tBProductBlockDetailsDTO);

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