package vn.azteam.tpf.service.mapper;

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

import org.mapstruct.*;

/**
 * Mapper for the entity TBAddress and its DTO TBAddressDTO.
 */
@Mapper(componentModel = "spring", uses = {TBCountryMapper.class, TBCityMapper.class, TBDistrictMapper.class, TBWardMapper.class})
public interface TBAddressMapper extends EntityMapper<TBAddressDTO, TBAddress> {

    @Mapping(source = "tbCountry.id", target = "tbCountryId")
    @Mapping(source = "tbCountry.name", target = "tbCountryName")
    @Mapping(source = "tbCity.id", target = "tbCityId")
    @Mapping(source = "tbCity.name", target = "tbCityName")
    @Mapping(source = "tbDistrict.id", target = "tbDistrictId")
    @Mapping(source = "tbDistrict.name", target = "tbDistrictName")
    @Mapping(source = "tbWard.id", target = "tbWardId")
    @Mapping(source = "tbWard.name", target = "tbWardName")
    TBAddressDTO toDto(TBAddress tBAddress);

    @Mapping(source = "tbCountryId", target = "tbCountry")
    @Mapping(source = "tbCityId", target = "tbCity")
    @Mapping(source = "tbDistrictId", target = "tbDistrict")
    @Mapping(source = "tbWardId", target = "tbWard")
    TBAddress toEntity(TBAddressDTO tBAddressDTO);

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