package de.champonthis.buntspecht.model;

import java.time.Instant;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;

@Entity
@Table(name = "turnovers")
public class Turnover {

    @Id
    @Column(name = "id", updatable = false, unique = true, nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

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

    @Column(name = "created", nullable = false, updatable = false)
    private Instant created;

    @Column(name = "due_date", nullable = false)
    private Instant dueDate;

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

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

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

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

    @Column(name = "payment_method", nullable = true)
    private String paymentMethod;

    @Column(name = "time_investment", nullable = true)
    private float timeInvestment;

    @Lob
    @Column(name = "remark", nullable = true, length = 5000)
    private String remark;

    @Lob
    @Column(name = "material_consumption", nullable = true, length = 5000)
    private String materialConsumption;

    @Column(name = "giftcard_number", nullable = true)
    private String giftcardNumber;

    @Column(name = "giftcard_price", nullable = true)
    private Float giftcardPrice;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Instant getCreated() {
        return created;
    }

    public void setCreated(Instant created) {
        this.created = created;
    }

    public Instant getDueDate() {
        return dueDate;
    }

    public void setDueDate(Instant dueDate) {
        this.dueDate = dueDate;
    }

    public Instant getUpdated() {
        return updated;
    }

    public void setUpdated(Instant updated) {
        this.updated = updated;
    }

    public String getCustomer() {
        return customer;
    }

    public void setCustomer(String customer) {
        this.customer = customer;
    }

    public String getMotif() {
        return motif;
    }

    public void setMotif(String motif) {
        this.motif = motif;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public String getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(String paymentMethod) {
        this.paymentMethod = paymentMethod;
    }

    public float getTimeInvestment() {
        return timeInvestment;
    }

    public void setTimeInvestment(float timeInvestment) {
        this.timeInvestment = timeInvestment;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getMaterialConsumption() {
        return materialConsumption;
    }

    public void setMaterialConsumption(String materialConsumption) {
        this.materialConsumption = materialConsumption;
    }

    public String getGiftcardNumber() {
        return giftcardNumber;
    }

    public void setGiftcardNumber(String giftcardNumber) {
        this.giftcardNumber = giftcardNumber;
    }

    public Float getGiftcardPrice() {
        return giftcardPrice;
    }

    public void setGiftcardPrice(Float giftcardPrice) {
        this.giftcardPrice = giftcardPrice;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof Turnover)) {
            return false;
        }
        Turnover turnover = (Turnover) obj;
        boolean equals = true;

        equals &= dueDate == null && turnover.getDueDate() == null
                || dueDate != null && dueDate.equals(turnover.getDueDate());

        equals &= id == null && turnover.getId() == null || id != null && id.equals(turnover.getId());

        equals &= username == null && turnover.getUsername() == null
                || username != null && username.equals(turnover.getUsername());

        equals &= customer == null && turnover.getCustomer() == null
                || customer != null && customer.equals(turnover.getCustomer());

        equals &= motif == null && turnover.getMotif() == null || motif != null && motif.equals(turnover.getMotif());

        equals &= price == turnover.getPrice();

        equals &= paymentMethod == null && turnover.getPaymentMethod() == null
                || paymentMethod != null && paymentMethod.equals(turnover.getPaymentMethod());

        equals &= timeInvestment == turnover.getTimeInvestment();

        equals &= remark == null && turnover.getRemark() == null
                || remark != null && remark.equals(turnover.getRemark());

        equals &= materialConsumption == null && turnover.getMaterialConsumption() == null
                || materialConsumption != null && materialConsumption.equals(turnover.getMaterialConsumption());

        equals &= giftcardNumber == null && turnover.getGiftcardNumber() == null
                || giftcardNumber != null && giftcardNumber.equals(turnover.getGiftcardNumber());

        equals &= giftcardPrice == null && turnover.getGiftcardPrice() == null
                || giftcardPrice != null && giftcardPrice.equals(turnover.getGiftcardPrice());

        return equals;
    }
}
