package org.springblade.modules.ldt.shop.wrapper;

/**
 * Created By lidexi in 2021/8/2
 **/

import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.modules.ldt.mall.entity.Mall;
import org.springblade.modules.ldt.mall.service.IMallService;
import org.springblade.modules.ldt.mallarea.entity.MallArea;
import org.springblade.modules.ldt.mallarea.service.IMallAreaService;
import org.springblade.modules.ldt.mallshoplabel.service.IMallShopLabelService;
import org.springblade.modules.ldt.shop.entity.Shop;
import org.springblade.modules.ldt.shop.vo.ShopVO;

import java.util.Objects;


/**
 * 包装类,返回视图层所需的字段
 *
 * @author Chill
 */
public class ShopWrapper extends BaseEntityWrapper<Shop, ShopVO> {

	private IMallAreaService mallAreaService;
	private IMallService mallService;

	private ShopWrapper(IMallAreaService mallAreaService,IMallService mallService){
		this.mallAreaService = mallAreaService;
		this.mallService = mallService;
	}

	public static ShopWrapper build(IMallAreaService mallAreaService,IMallService mallService) {
		return new ShopWrapper(mallAreaService,mallService);
	}

	@Override
	public ShopVO entityVO(Shop shop) {
		ShopVO shopVO = Objects.requireNonNull(BeanUtil.copy(shop, ShopVO.class));
		MallArea mallArea = mallAreaService.getById(shop.getMallAreaId());
		if(mallArea != null){
			shopVO.setMallAreaName(mallArea.getName());
		}
		Mall mall = mallService.getById(shop.getMallId());
		if(mall != null){
			shopVO.setMallName(mall.getName());
		}

		return shopVO;
	}



}

