package com.dne.ems.model;

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

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 污染物超标阈值设置实体类
 * 用于存储不同污染物的超标阈值设置
 */
@Data
@Entity
@Table(name = "pollutant_thresholds")
@NoArgsConstructor
public class PollutantThreshold {
    
    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /**
     * 污染物类型
     */
    @Enumerated(EnumType.STRING)
    @Column(nullable = false, unique = true)
    private PollutionType pollutionType;
    
    /**
     * 污染物名称
     */
    @Column(nullable = false, unique = true)
    private String pollutantName;
    
    /**
     * 超标阈值
     */
    @Column(nullable = false)
    private Double threshold;
    
    /**
     * 单位
     */
    @Column(nullable = false)
    private String unit;
    
    /**
     * 描述
     */
    private String description;
    
    /**
     * 构造函数
     * 
     * @param pollutantName 污染物名称
     * @param threshold 超标阈值
     * @param unit 单位
     * @param description 描述
     */
    public PollutantThreshold(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;
    }
    
    /**
     * 使用枚举类型的构造函数
     * 
     * @param pollutionType 污染物类型
     * @param threshold 超标阈值
     * @param unit 单位
     * @param description 描述
     */
    public PollutantThreshold(PollutionType pollutionType, Double threshold, String unit, String description) {
        this.pollutionType = pollutionType;
        this.pollutantName = pollutionType.name();
        this.threshold = threshold;
        this.unit = unit;
        this.description = description;
    }
} 