package de.cannamanage.domain.entity;

import de.cannamanage.domain.enums.SensorReadingType;
import jakarta.persistence.*;

import java.math.BigDecimal;
import java.time.Instant;
import java.util.UUID;

@Entity
@Table(name = "sensor_readings")
public class SensorReading {

    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    @Column(name = "id", nullable = false, updatable = false)
    private UUID id;

    @Column(name = "grow_entry_id", nullable = false)
    private UUID growEntryId;

    @Enumerated(EnumType.STRING)
    @Column(name = "reading_type", nullable = false, length = 30)
    private SensorReadingType readingType;

    @Column(name = "value", nullable = false, precision = 8, scale = 2)
    private BigDecimal value;

    @Column(name = "unit", nullable = false, length = 10)
    private String unit;

    @Column(name = "recorded_at", nullable = false)
    private Instant recordedAt;

    @PrePersist
    void onCreate() {
        if (this.recordedAt == null) this.recordedAt = Instant.now();
    }

    public UUID getId() { return id; }
    public void setId(UUID id) { this.id = id; }

    public UUID getGrowEntryId() { return growEntryId; }
    public void setGrowEntryId(UUID growEntryId) { this.growEntryId = growEntryId; }

    public SensorReadingType getReadingType() { return readingType; }
    public void setReadingType(SensorReadingType readingType) { this.readingType = readingType; }

    public BigDecimal getValue() { return value; }
    public void setValue(BigDecimal value) { this.value = value; }

    public String getUnit() { return unit; }
    public void setUnit(String unit) { this.unit = unit; }

    public Instant getRecordedAt() { return recordedAt; }
    public void setRecordedAt(Instant recordedAt) { this.recordedAt = recordedAt; }
}
