package com.ruoyi.web.domain.vo.FacilityManagement;

import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.web.domain.entity.FacilityManagement;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * 设施VO转换工厂
 */
public class FacilityVOFactory {

    private static final Map<String, Function<FacilityManagement, ? extends BaseFacilityVO>> CONVERTERS =
            new HashMap<>();

    static {
        CONVERTERS.put("1", entity -> {
            RoadVO vo = new RoadVO();
            BeanUtils.copyProperties(entity, vo);
            return vo;
        });

        CONVERTERS.put("2", entity -> {
            ElectricVO vo = new ElectricVO();
            BeanUtils.copyProperties(entity, vo);
            return vo;
        });

        CONVERTERS.put("3", entity -> {
            TelecomVO vo = new TelecomVO();
            BeanUtils.copyProperties(entity, vo);
            return vo;
        });

        CONVERTERS.put("4", entity -> {
            SchoolVO vo = new SchoolVO();
            BeanUtils.copyProperties(entity, vo);
            return vo;
        });


    }

    public static BaseFacilityVO convert(FacilityManagement entity) {
        Function<FacilityManagement, ? extends BaseFacilityVO> converter =
                CONVERTERS.get(entity.getFacilityType());
        if (converter == null) {
            throw new IllegalArgumentException("未知设施类型: " + entity.getFacilityType());
        }
        return converter.apply(entity);
    }
}