package com.dne.ems.dto;

import com.dne.ems.model.enums.PollutionType;

/**
 * 污染物阈值数据传输对象
 * 
 * <p>该类用于封装污染物的阈值相关信息，包括污染物类型、名称、阈值值、单位和描述等。
 * 主要用于环境监测系统中污染物标准管理和阈值展示。</p>
 *
 * <p>提供了多种构造方法，支持通过污染物类型枚举或污染物名称字符串创建对象。
 * 当使用名称字符串创建时，会尝试将其转换为对应的PollutionType枚举值。</p>
 *
 * @version 1.0
 * @since 2024
 * @see com.dne.ems.model.enums.PollutionType 污染物类型枚举
 */
public class PollutantThresholdDTO {
    /**
     * 污染物类型枚举
     */
    private PollutionType pollutionType;
    
    /**
     * 污染物名称
     */
    private String pollutantName;
    
    /**
     * 污染物阈值
     */
    private Double threshold;
    
    /**
     * 阈值单位（如mg/m³, μg/m³等）
     */
    private String unit;
    
    /**
     * 污染物及阈值的描述说明
     */
    private String description;
    
    /**
     * 默认构造函数
     */
    public PollutantThresholdDTO() {
    }
    
    /**
     * 全参数构造函数
     * 
     * @param pollutionType 污染物类型
     * @param pollutantName 污染物名称
     * @param threshold 阈值
     * @param unit 单位
     * @param description 描述
     */
    public PollutantThresholdDTO(PollutionType pollutionType, String pollutantName, Double threshold, String unit, String description) {
        this.pollutionType = pollutionType;
        this.pollutantName = pollutantName;
        this.threshold = threshold;
        this.unit = unit;
        this.description = description;
    }
    
    /**
     * 使用污染物名称的构造函数
     * 
     * @param pollutantName 污染物名称
     * @param threshold 阈值
     * @param unit 单位
     * @param description 描述
     */
    public PollutantThresholdDTO(String pollutantName, Double threshold, String unit, String description) {
        this.pollutantName = pollutantName;
        try {
            this.pollutionType = PollutionType.valueOf(pollutantName);
        } catch (IllegalArgumentException e) {
            // 如果不是有效的枚举值，默认为OTHER
            this.pollutionType = PollutionType.OTHER;
        }
        this.threshold = threshold;
        this.unit = unit;
        this.description = description;
    }
    
    // Getters and Setters
    public PollutionType getPollutionType() {
        return pollutionType;
    }
    
    public void setPollutionType(PollutionType pollutionType) {
        this.pollutionType = pollutionType;
        this.pollutantName = pollutionType.name();
    }
    
    public String getPollutantName() {
        return pollutantName;
    }
    
    public void setPollutantName(String pollutantName) {
        this.pollutantName = pollutantName;
        try {
            this.pollutionType = PollutionType.valueOf(pollutantName);
        } catch (IllegalArgumentException e) {
            // 如果不是有效的枚举值，默认为OTHER
            this.pollutionType = PollutionType.OTHER;
        }
    }
    
    public Double getThreshold() {
        return threshold;
    }
    
    public void setThreshold(Double threshold) {
        this.threshold = threshold;
    }
    
    public String getUnit() {
        return unit;
    }
    
    public void setUnit(String unit) {
        this.unit = unit;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
}