package digital.laboratory.platform.inspection.vo;

import com.baomidou.mybatisplus.annotation.TableName;
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;

/**
 * 样本检验数据的扩展信息
 * @TableName b_test_record_sampledata_expand
 */
@Data
@TableName(autoResultMap = true)
@ApiModel(value = "TestRecordSampleDataExpandVO", description = "样本检验数据的扩展信息 VO类") // 定义模型描述
public class TestRecordSampleDataExpandVO {

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

    @ApiModelProperty(value = "关联的实验数据id", example = "testData_001")
    private String testDataId;

    @ApiModelProperty(value = "峰面积", example = "12345.67")
    private BigDecimal peakArea;

    @ApiModelProperty(value = "是否是基峰, 1 是 | 0 不是", example = "true")
    private Boolean basePeak;

    @ApiModelProperty(value = "离子丰度比", example = "0.85")
    private BigDecimal ionAbundanceRatio;

    @ApiModelProperty(value = "离子丰度比相对偏差（%）",
            example = "5.2", notes = "计算公式：(目标物离子丰度比 - 标准物离子丰度比) / 标准物质离子丰度比 * 100")
    private BigDecimal ionAbundanceRatioError;

    @ApiModelProperty(value = "离子丰度比偏差是否在误差范围内", example = "是")
    private String ionAbundanceRatioWithinError;

    @ApiModelProperty(value = "碎片保留时间，仅对nps实验有用", example = "2.34")
    private BigDecimal fragmentRetTime;

    @ApiModelProperty(value = "质荷比(m/z)，nps案件", example = "150.2")
    private BigDecimal massToChargeRatio;

    @ApiModelProperty(value = "定性离子对，生物案件使用", example = "C6H12O6")
    private String qualitativeIonPair;

    /************************  处理需要特定格式返回的字段  **************************/

    public String getIonAbundanceRatio() {
        if (getBasePeak()) {
            return TestRecordSampleDataConstant.INVALID_VALUE_STR;
        }
        return ionAbundanceRatio != null ? ionAbundanceRatio.setScale(2, RoundingMode.HALF_UP).toString() : null;
    }

    public String getIonAbundanceRatioError() {
        if (getBasePeak()) {
            return TestRecordSampleDataConstant.INVALID_VALUE_STR;
        }
        return ionAbundanceRatioError != null ? ionAbundanceRatioError.setScale(2, RoundingMode.HALF_UP).toString() : null;
    }

    public String getIonAbundanceRatioWithinError() {
        if (getBasePeak()) {
            return TestRecordSampleDataConstant.INVALID_VALUE_STR;
        }
        return ionAbundanceRatioWithinError;
    }
}

