package it.integry.integrywmsnative.core.data_store.db.entity;

import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.PrimaryKey;

import java.math.BigDecimal;
import java.time.LocalDateTime;

import it.integry.integrywmsnative.core.data_store.db.interfaces.EntityModelInterface;

@Entity(
        tableName = InventarioRowRoomDTO.TABLE_NAME,
        foreignKeys = {
                @ForeignKey(
                        entity = InventarioRoomDTO.class,
                        parentColumns = {BaseSyncDTO.Columns.ID},
                        childColumns = {InventarioRowRoomDTO.Columns.PARENT_ID},
                        onDelete = ForeignKey.CASCADE
                )
        }
)
public class InventarioRowRoomDTO extends BaseSyncDTO implements EntityModelInterface {

    public static final String TABLE_NAME = "inventario_rows";

    public static class Columns {
        public static final String PARENT_ID = "parent_id";
        public static final String COD_MART = "cod_mart";
        public static final String PARTITA_MAG = "partita_mag";
        public static final String DESCRIZIONE = "descrizione";
        public static final String QTA = "qta";
        public static final String NUM_CNF = "num_cnf";
        public static final String QTA_CNF = "qta_cnf";
        public static final String UNT_MIS = "unt_mis";
        public static final String DATA_ORA_INV = "data_ora_inv";
        public static final String SCAN_COD_BARRE = "scan_cod_barre";
        public static final String ZONA = "zona";
    }

    /**
     * The unique ID
     */
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(index = true, name = BaseSyncDTO.Columns.ID)
    private Long id;

    @ColumnInfo(index = true, name = Columns.PARENT_ID)
    private Long parentId;

    @ColumnInfo(name = Columns.COD_MART)
    private String codMart;

    @ColumnInfo(name = Columns.PARTITA_MAG)
    private String partitaMag;

    @ColumnInfo(name = Columns.DESCRIZIONE)
    private String descrizione;

    @NonNull
    @ColumnInfo(name = Columns.QTA, defaultValue = "0")
    private BigDecimal qta;

    @NonNull
    @ColumnInfo(name = Columns.NUM_CNF, defaultValue = "0")
    private BigDecimal numConf;

    @NonNull
    @ColumnInfo(name = Columns.QTA_CNF, defaultValue = "0")
    private BigDecimal qtaConf;

    @NonNull
    @ColumnInfo(name = Columns.UNT_MIS, defaultValue = "0")
    private String untMis;

    @ColumnInfo(name = Columns.DATA_ORA_INV)
    private LocalDateTime dataOraInv;

    @ColumnInfo(name = Columns.SCAN_COD_BARRE)
    private String scanCodBarre;

    @ColumnInfo(name = Columns.ZONA)
    private String zona;


    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getCodMart() {
        return codMart;
    }

    public void setCodMart(@NonNull String codMart) {
        this.codMart = codMart;
    }

    public String getPartitaMag() {
        return partitaMag;
    }

    public void setPartitaMag(String partitaMag) {
        this.partitaMag = partitaMag;
    }

    public String getDescrizione() {
        return descrizione;
    }

    public void setDescrizione(String descrizione) {
        this.descrizione = descrizione;
    }

    @NonNull
    public BigDecimal getQta() {
        return qta;
    }

    public void setQta(@NonNull BigDecimal qta) {
        this.qta = qta;
    }

    @NonNull
    public BigDecimal getNumConf() {
        return numConf;
    }

    public void setNumConf(@NonNull BigDecimal numConf) {
        this.numConf = numConf;
    }

    @NonNull
    public BigDecimal getQtaConf() {
        return qtaConf;
    }

    public void setQtaConf(@NonNull BigDecimal qtaConf) {
        this.qtaConf = qtaConf;
    }

    @NonNull
    public String getUntMis() {
        return untMis;
    }

    public void setUntMis(@NonNull String untMis) {
        this.untMis = untMis;
    }

    public LocalDateTime getDataOraInv() {
        return dataOraInv;
    }

    public void setDataOraInv(LocalDateTime dataOraInv) {
        this.dataOraInv = dataOraInv;
    }

    public String getScanCodBarre() {
        return scanCodBarre;
    }

    public void setScanCodBarre(String scanCodBarre) {
        this.scanCodBarre = scanCodBarre;
    }

    public String getZona() {
        return zona;
    }

    public void setZona(String zona) {
        this.zona = zona;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        InventarioRowRoomDTO that = (InventarioRowRoomDTO) o;

        if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null) return false;
        if (getParentId() != null ? !getParentId().equals(that.getParentId()) : that.getParentId() != null)
            return false;
        if (getCodMart() != null ? !getCodMart().equals(that.getCodMart()) : that.getCodMart() != null)
            return false;
        if (getPartitaMag() != null ? !getPartitaMag().equals(that.getPartitaMag()) : that.getPartitaMag() != null)
            return false;
        if (getDescrizione() != null ? !getDescrizione().equals(that.getDescrizione()) : that.getDescrizione() != null)
            return false;
        if (!getQta().equals(that.getQta())) return false;
        if (!getNumConf().equals(that.getNumConf())) return false;
        if (!getQtaConf().equals(that.getQtaConf())) return false;
        if (!getUntMis().equals(that.getUntMis())) return false;
        if (getDataOraInv() != null ? !getDataOraInv().equals(that.getDataOraInv()) : that.getDataOraInv() != null)
            return false;
        if (getScanCodBarre() != null ? !getScanCodBarre().equals(that.getScanCodBarre()) : that.getScanCodBarre() != null)
            return false;
        return getZona() != null ? getZona().equals(that.getZona()) : that.getZona() == null;
    }

    @Override
    public int hashCode() {
        int result = getId() != null ? getId().hashCode() : 0;
        result = 31 * result + (getParentId() != null ? getParentId().hashCode() : 0);
        result = 31 * result + (getCodMart() != null ? getCodMart().hashCode() : 0);
        result = 31 * result + (getPartitaMag() != null ? getPartitaMag().hashCode() : 0);
        result = 31 * result + (getDescrizione() != null ? getDescrizione().hashCode() : 0);
        result = 31 * result + getQta().hashCode();
        result = 31 * result + getNumConf().hashCode();
        result = 31 * result + getQtaConf().hashCode();
        result = 31 * result + getUntMis().hashCode();
        result = 31 * result + (getDataOraInv() != null ? getDataOraInv().hashCode() : 0);
        result = 31 * result + (getScanCodBarre() != null ? getScanCodBarre().hashCode() : 0);
        result = 31 * result + (getZona() != null ? getZona().hashCode() : 0);
        return result;
    }
}
