package de.cannamanage.domain.entity;

import jakarta.persistence.*;

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

/**
 * Tracks monthly distribution totals per member per calendar month.
 * One row per (member_id, year, month) — unique constraint enforced at DB level.
 * @Version for optimistic locking — concurrent distribution processing must not corrupt totals.
 */
@Entity
@Table(name = "monthly_quotas",
    uniqueConstraints = {
        @UniqueConstraint(columnNames = {"member_id", "year", "month"})
    }
)
public class MonthlyQuota extends AbstractTenantEntity {

    @Column(name = "member_id", nullable = false)
    private UUID memberId;

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

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

    @Column(name = "total_distributed", nullable = false, precision = 10, scale = 2)
    private BigDecimal totalDistributed = BigDecimal.ZERO;

    @Column(name = "max_allowed", nullable = false, precision = 10, scale = 2)
    private BigDecimal maxAllowed;

    @Version
    @Column(name = "version", nullable = false)
    private Long version = 0L;

    public UUID getMemberId() { return memberId; }
    public void setMemberId(UUID memberId) { this.memberId = memberId; }

    public Integer getYear() { return year; }
    public void setYear(Integer year) { this.year = year; }

    public Integer getMonth() { return month; }
    public void setMonth(Integer month) { this.month = month; }

    public BigDecimal getTotalDistributed() { return totalDistributed; }
    public void setTotalDistributed(BigDecimal totalDistributed) { this.totalDistributed = totalDistributed; }

    public BigDecimal getMaxAllowed() { return maxAllowed; }
    public void setMaxAllowed(BigDecimal maxAllowed) { this.maxAllowed = maxAllowed; }

    public Long getVersion() { return version; }
    public void setVersion(Long version) { this.version = version; }
}
