package vn.azteam.tpf.service.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import vn.azteam.tpf.domain.TBCode;
import vn.azteam.tpf.domain.TBCodeDetails;
import vn.azteam.tpf.service.dto.TBCodeDTO;

@Mapper(componentModel = "spring", uses = {TBDetailUserMapper.class})
public interface TBCodeMapper extends EntityMapper<TBCodeDTO, TBCode> {
    @Mapping(source = "createdBy.id", target = "createdById")
    @Mapping(source = "modifiedBy.id", target = "modifiedById")
    @Mapping(source = "deletedBy.id", target = "deletedById")
    TBCodeDTO toDto(TBCode tbCode);

    @Mapping(source = "tbCrop", target = "tbCrop")
    @Mapping(source = "createdById", target = "createdBy")
    @Mapping(source = "modifiedById", target = "modifiedBy")
    @Mapping(source = "deletedById", target = "deletedBy")
    TBCode toEntity(TBCodeDTO tBCodeDTO);

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