package de.effigenix.infrastructure.masterdata.persistence.entity;

import jakarta.persistence.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "frame_contracts")
public class FrameContractEntity {

    @Id
    @Column(name = "id", nullable = false, length = 36)
    private String id;

    @Column(name = "customer_id", nullable = false, unique = true, length = 36)
    private String customerId;

    @Column(name = "valid_from")
    private LocalDate validFrom;

    @Column(name = "valid_until")
    private LocalDate validUntil;

    @Column(name = "delivery_rhythm", nullable = false, length = 20)
    private String deliveryRhythm;

    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "contract_line_items", joinColumns = @JoinColumn(name = "frame_contract_id"))
    private List<ContractLineItemEmbeddable> lineItems = new ArrayList<>();

    protected FrameContractEntity() {}

    public FrameContractEntity(String id, String customerId, LocalDate validFrom,
                               LocalDate validUntil, String deliveryRhythm) {
        this.id = id;
        this.customerId = customerId;
        this.validFrom = validFrom;
        this.validUntil = validUntil;
        this.deliveryRhythm = deliveryRhythm;
    }

    public String getId() { return id; }
    public String getCustomerId() { return customerId; }
    public LocalDate getValidFrom() { return validFrom; }
    public LocalDate getValidUntil() { return validUntil; }
    public String getDeliveryRhythm() { return deliveryRhythm; }
    public List<ContractLineItemEmbeddable> getLineItems() { return lineItems; }

    public void setId(String id) { this.id = id; }
    public void setCustomerId(String customerId) { this.customerId = customerId; }
    public void setValidFrom(LocalDate validFrom) { this.validFrom = validFrom; }
    public void setValidUntil(LocalDate validUntil) { this.validUntil = validUntil; }
    public void setDeliveryRhythm(String deliveryRhythm) { this.deliveryRhythm = deliveryRhythm; }
    public void setLineItems(List<ContractLineItemEmbeddable> lineItems) { this.lineItems = lineItems; }
}
