package gc.mda.kcg.domain.sensor;

import jakarta.persistence.*;
import lombok.*;

import java.time.Instant;

@Entity
@Table(
    name = "pressure_readings",
    schema = "kcg",
    uniqueConstraints = @UniqueConstraint(columnNames = {"station", "reading_time"})
)
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PressureReading {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, length = 50)
    private String station;

    @Column(nullable = false)
    private double lat;

    @Column(nullable = false)
    private double lng;

    @Column(nullable = false)
    private double pressureHpa;

    @Column(nullable = false)
    private Instant readingTime;

    @Column(nullable = false)
    private Instant collectedAt;

    @PrePersist
    protected void onCreate() {
        if (collectedAt == null) {
            collectedAt = Instant.now();
        }
    }
}
