package com.zt.plat.module.base.service.masterdatasync.support;

import com.zt.plat.module.base.dal.dataobject.masterdata.MdmMaterialViewDO;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.time.format.DateTimeFormatter;
import java.util.function.Function;

/**
 * 源视图字段与物料属性定义之间的标准映射关系。
 */
@Getter
@RequiredArgsConstructor
public enum MasterDataPropertyDefinition {

    BASE_UNIT_CODE("mtrlBaseUnitCode", "基本计量单位编码", 50L, MdmMaterialViewDO::getBaseUnitCode, "STRING"),
    BASE_UNIT_NAME("mtrlBaseUnitName", "基本计量单位描述", 60L, MdmMaterialViewDO::getBaseUnitName, "STRING"),
    SHORT_DESCRIPTION("mtrlShortDesc", "短描述", 70L, MdmMaterialViewDO::getShortDescription, "STRING"),
    LONG_DESCRIPTION("mtrlLongDesc", "长描述", 80L, MdmMaterialViewDO::getLongDescription, "STRING"),
    CHALCO_CODE("mtrlChalcoCode", "中铝编码", 90L, MdmMaterialViewDO::getChalcoCode, "STRING"),
    ZHONGTONG_CODE("mtrlZhongtongCode", "中铜编码", 95L, MdmMaterialViewDO::getZhongtongCode, "STRING"),
    SPECIFICATION("mtrlSpecification", "规格", 100L, MdmMaterialViewDO::getSpecification, "STRING"),
    MODEL("mtrlModel", "型号", 110L, MdmMaterialViewDO::getModel, "STRING"),
    TEXTURE("mtrlTexture", "材质", 120L, MdmMaterialViewDO::getTexture, "STRING"),
    DRAWING_NUMBER("mtrlDrawingNumber", "图号", 130L, MdmMaterialViewDO::getDrawingNumber, "STRING"),
    ORDER_NUMBER("mtrlOrderNumber", "订货号", 140L, MdmMaterialViewDO::getOrderNumber, "STRING"),
    OTHER_PARAMETERS("mtrlOtherParameters", "其它参数", 150L, MdmMaterialViewDO::getOtherParameters, "STRING"),
    EQUIPMENT_CATEGORY("mtrlEquipmentCategory", "设备类别", 160L, MdmMaterialViewDO::getEquipmentCategory, "STRING"),
    MANUFACTURER("mtrlManufacturer", "主机生产商", 170L, MdmMaterialViewDO::getManufacturer, "STRING"),
    SOURCE("mtrlSource", "来源", 180L, MdmMaterialViewDO::getSource, "STRING"),
    RECORD_TIME("mtrlRecordTime", "记录时间", 190L,
            source -> source.getRecordTime() == null ? null : source.getRecordTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
            "DATETIME");

    private final String code;
    private final String displayName;
    private final long sort;
    private final Function<MdmMaterialViewDO, String> extractor;
    private final String dataType;

    public String extractValue(MdmMaterialViewDO source) {
        if (source == null) {
            return null;
        }
        String value = extractor.apply(source);
        if (value == null) {
            return null;
        }
        value = value.trim();
        return value.isEmpty() ? null : value;
    }
}
