package de.effigenix.domain.inventory;

import de.effigenix.shared.common.Quantity;

import java.time.Instant;
import java.util.List;
import java.util.Objects;

public class Reservation {

    private final ReservationId id;
    private final ReferenceType referenceType;
    private final String referenceId;
    private final Quantity quantity;
    private final ReservationPriority priority;
    private final Instant reservedAt;
    private final List<StockBatchAllocation> allocations;

    public Reservation(ReservationId id, ReferenceType referenceType, String referenceId,
                       Quantity quantity, ReservationPriority priority, Instant reservedAt,
                       List<StockBatchAllocation> allocations) {
        this.id = Objects.requireNonNull(id);
        this.referenceType = Objects.requireNonNull(referenceType);
        this.referenceId = Objects.requireNonNull(referenceId);
        this.quantity = Objects.requireNonNull(quantity);
        this.priority = Objects.requireNonNull(priority);
        this.reservedAt = Objects.requireNonNull(reservedAt);
        this.allocations = List.copyOf(allocations);
    }

    public ReservationId id() { return id; }
    public ReferenceType referenceType() { return referenceType; }
    public String referenceId() { return referenceId; }
    public Quantity quantity() { return quantity; }
    public ReservationPriority priority() { return priority; }
    public Instant reservedAt() { return reservedAt; }
    public List<StockBatchAllocation> allocations() { return allocations; }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (!(obj instanceof Reservation other)) return false;
        return Objects.equals(id, other.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
