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 = "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 = "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;

    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 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 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;
    }

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

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

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

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

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

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

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

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

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

        return equals;
    }
}
