package de.cannamanage.domain.entity;

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

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

@Entity
@Table(name = "grow_entries")
public class GrowEntry extends AbstractTenantEntity {

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

    @Column(name = "strain_id")
    private UUID strainId;

    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 30)
    private GrowStage status = GrowStage.SEEDLING;

    @Column(name = "started_at", nullable = false)
    private Instant startedAt;

    @Column(name = "expected_harvest_at")
    private Instant expectedHarvestAt;

    @Column(name = "actual_harvest_at")
    private Instant actualHarvestAt;

    @Column(name = "harvested_grams", precision = 8, scale = 1)
    private BigDecimal harvestedGrams;

    @Column(name = "linked_batch_id")
    private UUID linkedBatchId;

    @Column(name = "notes", columnDefinition = "TEXT")
    private String notes;

    @Column(name = "updated_at")
    private Instant updatedAt;

    @PrePersist
    void onCreateGrow() {
        if (this.startedAt == null) this.startedAt = Instant.now();
        this.updatedAt = Instant.now();
    }

    @PreUpdate
    void onUpdate() {
        this.updatedAt = Instant.now();
    }

    public String getName() { return name; }
    public void setName(String name) { this.name = name; }

    public UUID getStrainId() { return strainId; }
    public void setStrainId(UUID strainId) { this.strainId = strainId; }

    public GrowStage getStatus() { return status; }
    public void setStatus(GrowStage status) { this.status = status; }

    public Instant getStartedAt() { return startedAt; }
    public void setStartedAt(Instant startedAt) { this.startedAt = startedAt; }

    public Instant getExpectedHarvestAt() { return expectedHarvestAt; }
    public void setExpectedHarvestAt(Instant expectedHarvestAt) { this.expectedHarvestAt = expectedHarvestAt; }

    public Instant getActualHarvestAt() { return actualHarvestAt; }
    public void setActualHarvestAt(Instant actualHarvestAt) { this.actualHarvestAt = actualHarvestAt; }

    public BigDecimal getHarvestedGrams() { return harvestedGrams; }
    public void setHarvestedGrams(BigDecimal harvestedGrams) { this.harvestedGrams = harvestedGrams; }

    public UUID getLinkedBatchId() { return linkedBatchId; }
    public void setLinkedBatchId(UUID linkedBatchId) { this.linkedBatchId = linkedBatchId; }

    public String getNotes() { return notes; }
    public void setNotes(String notes) { this.notes = notes; }

    public Instant getUpdatedAt() { return updatedAt; }
    public void setUpdatedAt(Instant updatedAt) { this.updatedAt = updatedAt; }
}
