package vn.azteam.tpf.service.mapper;

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

import org.mapstruct.*;

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

    @Mapping(source = "tbDashboardType.id", target = "tbDashboardTypeId")
    @Mapping(source = "tbAddress.id", target = "tbAddressId")
    @Mapping(source = "tbAddress.tbCountry.id", target = "countryId")
    @Mapping(source = "tbAddress.tbCountry.name", target = "country")
    @Mapping(source = "tbAddress.tbCity.id", target = "cityId")
    @Mapping(source = "tbAddress.tbCity.name", target = "city")
    @Mapping(source = "tbAddress.tbDistrict.id", target = "districtId")
    @Mapping(source = "tbAddress.tbDistrict.name", target = "district")
    @Mapping(source = "tbAddress.tbWard.id", target = "wardId")
    @Mapping(source = "tbAddress.tbWard.name", target = "ward")
    @Mapping(source = "tbAddress.address", target = "address")
    @Mapping(source = "createdBy.id", target = "createdById")
    @Mapping(source = "modifiedBy.id", target = "modifiedById")
    @Mapping(source = "deletedBy.id", target = "deletedById")
    TBCustomerDTO toDto(TBCustomer tBCustomer);

    @Mapping(source = "tbDashboardTypeId", target = "tbDashboardType")
    @Mapping(source = "tbAddressId", target = "tbAddress")
    @Mapping(source = "createdById", target = "createdBy")
    @Mapping(source = "modifiedById", target = "modifiedBy")
    @Mapping(source = "deletedById", target = "deletedBy")
    TBCustomer toEntity(TBCustomerDTO tBCustomerDTO);

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