package vn.azteam.tpf.service.mapper;

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

import org.mapstruct.*;

/**
 * Mapper for the entity TBCrop and its DTO TBCropDTO.
 */
@Mapper(componentModel = "spring", uses = {TBSuppliesMapper.class, TBGuidelineMapper.class, TBEntityMapper.class, TBDetailUserMapper.class, TBCropTypeMapper.class})
public interface TBCropMapper extends EntityMapper<TBCropDTO, TBCrop> {

    @Mapping(source = "tbSupplies.id", target = "tbSuppliesId")
    @Mapping(source = "tbSupplies.name", target = "suppliesName")
    @Mapping(source = "tbGuideline.id", target = "tbGuidelineId")
    @Mapping(source = "tbGuideline.duration", target = "guidelineDuration")
    @Mapping(source = "tbEntity.id", target = "netHouseId")
    @Mapping(source = "tbEntity.name", target = "netHouseName")
    @Mapping(source = "tbEntity.tbEntity.id", target = "areaId")
    @Mapping(source = "tbEntity.tbEntity.name", target = "area")
    @Mapping(source = "createdBy.id", target = "createdById")
    @Mapping(source = "modifiedBy.id", target = "modifiedById")
    @Mapping(source = "deletedBy.id", target = "deletedById")
    @Mapping(source = "tbEntity.tbCustomer.id", target = "tbCustomerId")
    @Mapping(source = "tbCropType.id", target = "tbCropTypeId")
    @Mapping(target = "tbGuidelinePeriodId", ignore = true)
    @Mapping(target = "tbGuidelinePeriodName", ignore = true)
    TBCropDTO toDto(TBCrop tBCrop);

    @Mapping(source = "tbCropTypeId", target = "tbCropType")
    @Mapping(source = "tbSuppliesId", target = "tbSupplies")
    @Mapping(source = "tbGuidelineId", target = "tbGuideline")
    @Mapping(source = "netHouseId", target = "tbEntity")
    @Mapping(source = "createdById", target = "createdBy")
    @Mapping(source = "modifiedById", target = "modifiedBy")
    @Mapping(source = "deletedById", target = "deletedBy")
    TBCrop toEntity(TBCropDTO tBCropDTO);

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