package vn.azteam.tpf.service.mapper;

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

import org.mapstruct.*;

/**
 * Mapper for the entity TBEntity and its DTO TBEntityDTO.
 */
@Mapper(componentModel = "spring", uses = {TBAddressMapper.class, TBDetailUserMapper.class, TBCustomerMapper.class, TBEntityTypeMapper.class})
public interface TBEntityMapper extends EntityMapper<TBEntityDTO, TBEntity> {

    @Mapping(source = "tbEntity.id", target = "parentId")
    @Mapping(source = "tbAddress.id", target = "tbAddressId")
    @Mapping(source = "createdBy.id", target = "createdById")
    @Mapping(source = "modifiedBy.id", target = "modifiedById")
    @Mapping(source = "deletedBy.id", target = "deletedById")
    @Mapping(source = "tbCustomer.id", target = "tbCustomerId")
    @Mapping(source = "tbEntityType.id", target = "tbEntityTypeId")
    @Mapping(target = "detailUserDTOS", ignore = true)
    @Mapping(target = "color", ignore = true)
    @Mapping(target = "tbCropDTOS", ignore = true)
    @Mapping(target = "totalDevice", ignore = true)

    TBEntityDTO toDto(TBEntity tBEntity);

    @Mapping(source = "parentId", target = "tbEntity")
    @Mapping(source = "tbAddressId", target = "tbAddress")
    @Mapping(source = "createdById", target = "createdBy")
    @Mapping(source = "modifiedById", target = "modifiedBy")
    @Mapping(source = "deletedById", target = "deletedBy")
    @Mapping(source = "tbCustomerId", target = "tbCustomer")
    @Mapping(source = "tbEntityTypeId", target = "tbEntityType")
    TBEntity toEntity(TBEntityDTO tBEntityDTO);

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