package digital.laboratory.platform.inspection.convert;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import digital.laboratory.platform.inspection.entity.TestRecordReagent;
import digital.laboratory.platform.inspection.vo.TestRecordReagentVO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ChenJiangBao
 * @version 1.0
 * @description: 实验中用到的试剂耗材 的转换类
 * @date 2025/3/20 14:59
 */
public class TestRecordReagentConverter {

    /**
     * 实体类转vo类
     */
    public static TestRecordReagentVO entityToVO(TestRecordReagent entity) {
        if (entity == null) return null;
        TestRecordReagentVO testRecordReagentVO = new TestRecordReagentVO();
        testRecordReagentVO.setId(entity.getId());
        testRecordReagentVO.setDrugId(entity.getDrugId());
        testRecordReagentVO.setReagentConsumableName(entity.getReagentConsumableName());
        testRecordReagentVO.setCategory(entity.getCategory());
        testRecordReagentVO.setSpecifications(entity.getSpecifications());
        testRecordReagentVO.setPurityGrade(entity.getPurityGrade());
        testRecordReagentVO.setNumber(entity.getNumber());
        testRecordReagentVO.setSortIndex(entity.getSortIndex());
        testRecordReagentVO.setSource(entity.getSource());
        return testRecordReagentVO;
    }

    /**
     * 实体分页对象转 VO 分页对象
     */
    public static List<TestRecordReagentVO> entityToVOList(List<TestRecordReagent> entityList) {
        // 将实体列表转换为 VO 列表
        return entityList.stream().map(TestRecordReagentConverter::entityToVO).collect(Collectors.toList());
    }

    /**
     * 实体分页对象转 VO 分页对象
     */
    public static IPage<TestRecordReagentVO> entityToVOPage(IPage<TestRecordReagent> entityPage) {
        // 创建 VO 的分页对象
        IPage<TestRecordReagentVO> voPage = new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal());

        // 将实体列表转换为 VO 列表
        List<TestRecordReagentVO> voList = entityPage.getRecords().stream()
                .map(TestRecordReagentConverter::entityToVO)
                .collect(Collectors.toList());

        // 设置转换后的记录
        voPage.setRecords(voList);
        return voPage;
    }
}
