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

import jakarta.persistence.*;

import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Entity
@Table(name = "customers")
public class CustomerEntity {

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

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

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

    @Column(name = "phone", length = 50)
    private String phone;

    @Column(name = "email", length = 255)
    private String email;

    @Column(name = "contact_person", length = 200)
    private String contactPerson;

    @Column(name = "billing_street", nullable = false, length = 200)
    private String billingStreet;

    @Column(name = "billing_house_number", length = 20)
    private String billingHouseNumber;

    @Column(name = "billing_postal_code", nullable = false, length = 20)
    private String billingPostalCode;

    @Column(name = "billing_city", nullable = false, length = 100)
    private String billingCity;

    @Column(name = "billing_country", nullable = false, length = 2)
    private String billingCountry;

    @Column(name = "payment_due_days")
    private Integer paymentDueDays;

    @Column(name = "payment_description", length = 500)
    private String paymentDescription;

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

    @Column(name = "created_at", nullable = false, updatable = false)
    private OffsetDateTime createdAt;

    @Column(name = "updated_at", nullable = false)
    private OffsetDateTime updatedAt;

    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "delivery_addresses", joinColumns = @JoinColumn(name = "customer_id"))
    private List<DeliveryAddressEmbeddable> deliveryAddresses = new ArrayList<>();

    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "customer_preferences", joinColumns = @JoinColumn(name = "customer_id"))
    @Column(name = "preference")
    @Enumerated(EnumType.STRING)
    private Set<de.effigenix.domain.masterdata.CustomerPreference> preferences = new HashSet<>();

    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
    @JoinColumn(name = "id", referencedColumnName = "customer_id", insertable = false, updatable = false)
    private FrameContractEntity frameContract;

    public CustomerEntity() {}

    public String getId() { return id; }
    public String getName() { return name; }
    public String getType() { return type; }
    public String getPhone() { return phone; }
    public String getEmail() { return email; }
    public String getContactPerson() { return contactPerson; }
    public String getBillingStreet() { return billingStreet; }
    public String getBillingHouseNumber() { return billingHouseNumber; }
    public String getBillingPostalCode() { return billingPostalCode; }
    public String getBillingCity() { return billingCity; }
    public String getBillingCountry() { return billingCountry; }
    public Integer getPaymentDueDays() { return paymentDueDays; }
    public String getPaymentDescription() { return paymentDescription; }
    public String getStatus() { return status; }
    public OffsetDateTime getCreatedAt() { return createdAt; }
    public OffsetDateTime getUpdatedAt() { return updatedAt; }
    public List<DeliveryAddressEmbeddable> getDeliveryAddresses() { return deliveryAddresses; }
    public Set<de.effigenix.domain.masterdata.CustomerPreference> getPreferences() { return preferences; }
    public FrameContractEntity getFrameContract() { return frameContract; }

    public void setId(String id) { this.id = id; }
    public void setName(String name) { this.name = name; }
    public void setType(String type) { this.type = type; }
    public void setPhone(String phone) { this.phone = phone; }
    public void setEmail(String email) { this.email = email; }
    public void setContactPerson(String contactPerson) { this.contactPerson = contactPerson; }
    public void setBillingStreet(String billingStreet) { this.billingStreet = billingStreet; }
    public void setBillingHouseNumber(String billingHouseNumber) { this.billingHouseNumber = billingHouseNumber; }
    public void setBillingPostalCode(String billingPostalCode) { this.billingPostalCode = billingPostalCode; }
    public void setBillingCity(String billingCity) { this.billingCity = billingCity; }
    public void setBillingCountry(String billingCountry) { this.billingCountry = billingCountry; }
    public void setPaymentDueDays(Integer paymentDueDays) { this.paymentDueDays = paymentDueDays; }
    public void setPaymentDescription(String paymentDescription) { this.paymentDescription = paymentDescription; }
    public void setStatus(String status) { this.status = status; }
    public void setCreatedAt(OffsetDateTime createdAt) { this.createdAt = createdAt; }
    public void setUpdatedAt(OffsetDateTime updatedAt) { this.updatedAt = updatedAt; }
    public void setDeliveryAddresses(List<DeliveryAddressEmbeddable> deliveryAddresses) { this.deliveryAddresses = deliveryAddresses; }
    public void setPreferences(Set<de.effigenix.domain.masterdata.CustomerPreference> preferences) { this.preferences = preferences; }
    public void setFrameContract(FrameContractEntity frameContract) { this.frameContract = frameContract; }
}
