package vn.azteam.tpf.service.mapper;

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

import org.mapstruct.*;

/**
 * Mapper for the entity TBDetailUser and its DTO TBDetailUserDTO.
 */
@Mapper(componentModel = "spring", uses = {UserMapper.class, TBRoleMapper.class, TBCustomerMapper.class, TBAddressMapper.class})
public interface TBDetailUserMapper extends EntityMapper<TBDetailUserDTO, TBDetailUser> {

    @Mapping(source = "tbRole.id", target = "tbRoleId")
    @Mapping(source = "tbRole.name", target = "tbRoleName")
    @Mapping(source = "user.id", target = "userId")
    @Mapping(source = "tbCustomer.id", target = "tbCustomerId")
    @Mapping(source = "tbAddress.id", target = "tbAddressId")
    TBDetailUserDTO toDto(TBDetailUser tBDetailUser);

    @Mapping(source = "tbRoleId", target = "tbRole")
    @Mapping(source = "userId", target = "user")
    @Mapping(source = "tbCustomerId", target = "tbCustomer")
    @Mapping(source = "tbAddressId", target = "tbAddress")
    @Mapping(target = "tbCrops", ignore = true)
    TBDetailUser toEntity(TBDetailUserDTO tBDetailUserDTO);

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