package digital.laboratory.platform.inspection.vo;

import digital.laboratory.platform.inspection.constant.TestRecordSampleDataConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * 样本检验数据 VO类
 * @TableName b_test_record_sampledata
 */
@Data
@ApiModel(value = "TestRecordSampleDataVO", description = "实验中样本检测结果数据 VO类")
public class TestRecordSampleDataVO {

    @ApiModelProperty(value = "主键标识", example = "123456789")
    private String id;

    @ApiModelProperty(value = "数据从机器中导出的唯一标识", example = "Sample123")
    private String name;

    @ApiModelProperty(value = "样本编号", example = "SMP001")
    private String sampleNo;

    @ApiModelProperty(value = "实验ID", example = "TEST001")
    private String testId;

    @ApiModelProperty(value = "标准品浓度", example = "10.5")
    private String stdConcentration;

    @ApiModelProperty(value = "样品浓度", example = "8.9")
    private String sampleConcentration;

    @ApiModelProperty(value = "化合物名称", example = "Heroin")
    private String compoundName;

    @ApiModelProperty(value = "保留时间是否在误差范围内，缴获物(-1~1), 生物样本(-2.5~2.5)", example = "0.5")
    private String rtTimeWithinError;

    @ApiModelProperty(value = "保留时间相对误差(%)", example = "1.2")
    private BigDecimal rtTimeError;

    @ApiModelProperty(value = "检材保留时间(min)", example = "2.5")
    private Double targetRtTime;

    @ApiModelProperty(value = "标准品保留时间(min)", example = "2.6")
    private Double stdRtTime;

    @ApiModelProperty(value = "是否检出该物质 1 检出, 0 未检出", example = "1")
    private Integer isDetected;

    @ApiModelProperty(value = "样本类型 - QC(质控), STD(标准品), Analyte(待测样品)", example = "QC")
    private String sampleType;

    @ApiModelProperty(value = "检验数据 JSON", example = "{\"mass\": 146, \"intensity\": 200}")
    private String dataJson;

    @ApiModelProperty(value = "检验结果数据 JSON", example = "{\"result\": \"Positive\"}")
    private String dataResultJson;

    @ApiModelProperty(value = "状态：0-待审核, 1-已审核, 2-已审批, 3-已上传", example = "1")
    private Integer status;

    @ApiModelProperty(value = "检测的化合物的中文名字", example = "海洛因")
    private String compoundCnName;

    @ApiModelProperty("是否检出, 定性结果")
    private String whetherCheckOut;

    @ApiModelProperty("样本检验扩展数据列表")
    private List<TestRecordSampleDataExpandVO> expandList;

    /*********************************  对于返回到前端的数据进行处理  *****************************************/
    /**
     * 获取检测状态。
     *
     * @return 如果检测状态为已检测，则返回TestRecordSampleDataConstant.IS；
     *         如果检测状态为未检测，则返回TestRecordSampleDataConstant.NO；
     *         如果检测状态为空，则返回null。
     */
    public String getIsDetected() {
        if (isDetected == null) {
            return null;
        }
        return isDetected.equals(1) ? TestRecordSampleDataConstant.IS : TestRecordSampleDataConstant.NO;
    }

    public String getRtTimeError() {
        if (sampleType.equals(TestRecordSampleDataConstant.SAMPLE_TYPE_STD)) {
            return TestRecordSampleDataConstant.INVALID_VALUE_STR;
        }
        return rtTimeError != null ? rtTimeError.setScale(3, RoundingMode.HALF_UP).toString() : null;
    }

    /**
     * 该getter方法因为生物样本的丰度比只有一个，为前端显示而添加
     *
     * @return
     */
    public String getIonAbundanceRatioError() {
        return expandList != null && expandList.size() > 1 ? expandList.get(1).getIonAbundanceRatioError() : null;
    }

    public String getIonAbundanceRatio() {
        return expandList != null && expandList.size() > 1 ? expandList.get(1).getIonAbundanceRatio() : null;
    }

    public String getIonAbundanceRatioWithinError() {
        return expandList != null && expandList.size() > 1 ? expandList.get(1).getIonAbundanceRatioWithinError() : null;
    }

}
