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

import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.web.domain.entity.VillageSpecial;
import com.ruoyi.web.service.VillageSpecialService;
import org.springframework.beans.factory.annotation.Autowired;

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

/**
 * 特色产业VO转换工厂
 */
public class SpecialVOFactory {

    @Autowired
    private VillageSpecialService villageSpecialService;

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

    //0-保安腰刀产业、1-农家乐产业、2-民宿产业
    static {
        CONVERTERS.put("0", entity -> {
            BaoAnVO vo = new BaoAnVO();
            BeanUtils.copyProperties(entity, vo);
            return vo;
        });

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

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

    public static BaseVillageSpecialVO convert(VillageSpecial entity) {
        Function<VillageSpecial, ? extends BaseVillageSpecialVO> converter =
                CONVERTERS.get(entity.getCategory());
        if (converter == null) {
            throw new IllegalArgumentException("未知特色产业类型: " + entity.getCategory());
        }
        return converter.apply(entity);
    }
}