package it.integry.integrywmsnative.core.model;

import android.os.Parcel;
import android.os.Parcelable;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import it.integry.integrywmsnative.core.utility.UtilityExceptions;
import it.integry.integrywmsnative.core.utility.UtilityLogger;
import it.integry.integrywmsnative.core.utility.UtilityString;

public class MtbColr extends EntityBase implements Parcelable {


    private String gestione;
    private String serCollo;
    private Integer numCollo;
    private String dataCollo;
    private Integer riga;
    private Integer rigaOrd;
    private String codMart;
    private String codBarre;
    private String codCol;
    private String codTagl;
    private String partitaMag;
    private String gestioneRif;
    private String serColloRif;
    private String note;
    private String dataOrd;
    private String dataColloRif;
    private BigDecimal qtaCnf;
    private BigDecimal qtaCol;
    private Integer numOrd;
    private Integer numEtich;
    private Integer numColloRif;
    private String datetimeRow;
    private String codJcom;
    private BigDecimal numCnf;
    private String insPartitaMag;
    private String mtbPartitaMag_descrizione;
    private String dataScadPartita;
    private String descrizione;
    private String untMis;

    private MtbAart mtbAart;

    public MtbColr() {
        type = "mtb_colr";
    }


    protected MtbColr(Parcel in) {
        type = "mtb_colr";
        gestione = in.readString();
        serCollo = in.readString();
        if (in.readByte() == 0) {
            numCollo = null;
        } else {
            numCollo = in.readInt();
        }
        dataCollo = in.readString();
        if (in.readByte() == 0) {
            riga = null;
        } else {
            riga = in.readInt();
        }
        if (in.readByte() == 0) {
            rigaOrd = null;
        } else {
            rigaOrd = in.readInt();
        }
        codMart = in.readString();
        codBarre = in.readString();
        codCol = in.readString();
        codTagl = in.readString();
        partitaMag = in.readString();
        gestioneRif = in.readString();
        serColloRif = in.readString();
        note = in.readString();
        dataOrd = in.readString();
        dataColloRif = in.readString();
        if (in.readByte() == 0) {
            numOrd = null;
        } else {
            numOrd = in.readInt();
        }
        if (in.readByte() == 0) {
            numEtich = null;
        } else {
            numEtich = in.readInt();
        }
        if (in.readByte() == 0) {
            numColloRif = null;
        } else {
            numColloRif = in.readInt();
        }
        datetimeRow = in.readString();
        codJcom = in.readString();
        insPartitaMag = in.readString();
        mtbPartitaMag_descrizione = in.readString();
        dataScadPartita = in.readString();
        descrizione = in.readString();
        untMis = in.readString();

        if (in.readByte() == 0) {
            qtaCnf = null;
        } else {
            qtaCnf = new BigDecimal(in.readFloat());
        }

        if (in.readByte() == 0) {
            qtaCol = null;
        } else {
            qtaCol = new BigDecimal(in.readFloat());
        }

        if (in.readByte() == 0) {
            numCnf = null;
        } else {
            numCnf = new BigDecimal(in.readFloat());
        }

        mtbAart = in.readParcelable(MtbAart.class.getClassLoader());
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(gestione);
        dest.writeString(serCollo);
        if (numCollo == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(numCollo);
        }
        dest.writeString(dataCollo);
        if (riga == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(riga);
        }
        if (rigaOrd == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(rigaOrd);
        }
        dest.writeString(codMart);
        dest.writeString(codBarre);
        dest.writeString(codCol);
        dest.writeString(codTagl);
        dest.writeString(partitaMag);
        dest.writeString(gestioneRif);
        dest.writeString(serColloRif);
        dest.writeString(note);
        dest.writeString(dataOrd);
        dest.writeString(dataColloRif);
        if (numOrd == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(numOrd);
        }
        if (numEtich == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(numEtich);
        }
        if (numColloRif == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(numColloRif);
        }
        dest.writeString(datetimeRow);
        dest.writeString(codJcom);
        dest.writeString(insPartitaMag);
        dest.writeString(mtbPartitaMag_descrizione);
        dest.writeString(dataScadPartita);
        dest.writeString(descrizione);
        dest.writeString(untMis);

        if (qtaCnf == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeFloat(qtaCnf.floatValue());
        }

        if (qtaCol == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeFloat(qtaCol.floatValue());
        }

        if (numCnf == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeFloat(numCnf.floatValue());
        }

        dest.writeParcelable(mtbAart, flags);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<MtbColr> CREATOR = new Creator<MtbColr>() {
        @Override
        public MtbColr createFromParcel(Parcel in) {
            return new MtbColr(in);
        }

        @Override
        public MtbColr[] newArray(int size) {
            return new MtbColr[size];
        }
    };

    public String getGestione() {
        return gestione;
    }

    public MtbColr setGestione(String gestione) {
        this.gestione = gestione;
        return this;
    }

    public String getSerCollo() {
        return serCollo;
    }

    public MtbColr setSerCollo(String serCollo) {
        this.serCollo = serCollo;
        return this;
    }

    public Integer getNumCollo() {
        return numCollo;
    }

    public MtbColr setNumCollo(Integer numCollo) {
        this.numCollo = numCollo;
        return this;
    }

    public String getDataColloS() {
        return dataCollo;
    }

    public Date getDataColloD() {
        try{
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            return sdf.parse(getDataColloS());
        } catch (ParseException pex){
            UtilityLogger.errorMe(pex);
            return null;
        }
    }

    public MtbColr setDataCollo(String dataCollo) {
        this.dataCollo = dataCollo;
        return this;
    }


    public Integer getRiga() {
        return riga;
    }

    public MtbColr setRiga(Integer riga) {
        this.riga = riga;
        return this;
    }

    public Integer getRigaOrd() {
        return rigaOrd;
    }

    public MtbColr setRigaOrd(Integer rigaOrd) {
        this.rigaOrd = rigaOrd;
        return this;
    }

    public String getCodMart() {
        return codMart;
    }

    public MtbColr setCodMart(String codMart) {
        this.codMart = codMart;
        return this;
    }

    public String getCodBarre() {
        return codBarre;
    }

    public MtbColr setCodBarre(String codBarre) {
        this.codBarre = codBarre;
        return this;
    }

    public String getCodCol() {
        return codCol;
    }

    public MtbColr setCodCol(String codCol) {
        this.codCol = codCol;
        return this;
    }

    public String getCodTagl() {
        return codTagl;
    }

    public MtbColr setCodTagl(String codTagl) {
        this.codTagl = codTagl;
        return this;
    }

    public String getPartitaMag() {
        return partitaMag;
    }

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

    public String getGestioneRif() {
        return gestioneRif;
    }

    public MtbColr setGestioneRif(String gestioneRif) {
        this.gestioneRif = gestioneRif;
        return this;
    }

    public String getSerColloRif() {
        return serColloRif;
    }

    public MtbColr setSerColloRif(String serColloRif) {
        this.serColloRif = serColloRif;
        return this;
    }

    public String getNote() {
        return note;
    }

    public MtbColr setNote(String note) {
        this.note = note;
        return this;
    }

    public String getDataOrdS() {
        return dataOrd;
    }

    public Date getDataOrdD() {
        try{
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            return sdf.parse(getDataOrdS());
        } catch (ParseException pex){
            UtilityLogger.errorMe(pex);
            return null;
        }
    }

    public MtbColr setDataOrd(String dataOrd) {
        this.dataOrd = dataOrd;
        return this;
    }

    public MtbColr setDataOrd(Date dataOrd) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        this.dataOrd = sdf.format(dataOrd);
        return this;
    }

    public String getDataColloRifS() {
        return dataColloRif;
    }

    public Date getDataColloRifD() {
        try{
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            return sdf.parse(getDataColloRifS());
        } catch (ParseException pex){
            UtilityLogger.errorMe(pex);
            return null;
        }
    }

    public MtbColr setDataColloRif(String dataColloRif) {
        this.dataColloRif = dataColloRif;
        return this;
    }

    public MtbColr setDataColloRif(Date dataColloRif) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        this.dataColloRif = sdf.format(dataColloRif);
        return this;
    }

    public BigDecimal getQtaCnf() {
        return qtaCnf;
    }

    public MtbColr setQtaCnf(BigDecimal qtaCnf) {
        this.qtaCnf = qtaCnf;
        return this;
    }

    public BigDecimal getQtaCol() {
        return qtaCol;
    }

    public MtbColr setQtaCol(BigDecimal qtaCol) {
        this.qtaCol = qtaCol;
        return this;
    }

    public Integer getNumOrd() {
        return numOrd;
    }

    public MtbColr setNumOrd(Integer numOrd) {
        this.numOrd = numOrd;
        return this;
    }

    public Integer getNumEtich() {
        return numEtich;
    }

    public MtbColr setNumEtich(Integer numEtich) {
        this.numEtich = numEtich;
        return this;
    }

    public Integer getNumColloRif() {
        return numColloRif;
    }

    public MtbColr setNumColloRif(Integer numColloRif) {
        this.numColloRif = numColloRif;
        return this;
    }




    public String getDatetimeRowS() {
        return datetimeRow;
    }

    public Date getDatetimeRowD() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        return sdf.parse(getDatetimeRowS());
    }

    public MtbColr setDatetimeRow(String datetimeRow) {
        this.datetimeRow = datetimeRow;
        return this;
    }

    public MtbColr setDatetimeRow(Date datetimeRow) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        this.datetimeRow = sdf.format(datetimeRow);
        return this;
    }







    public String getCodJcom() {
        return codJcom;
    }

    public MtbColr setCodJcom(String codJcom) {
        this.codJcom = codJcom;
        return this;
    }

    public BigDecimal getNumCnf() {
        return numCnf;
    }

    public MtbColr setNumCnf(BigDecimal numCnf) {
        this.numCnf = numCnf;
        return this;
    }

    public String getInsPartitaMag() {
        return insPartitaMag;
    }

    public MtbColr setInsPartitaMag(String insPartitaMag) {
        this.insPartitaMag = insPartitaMag;
        return this;
    }

    public String getMtbPartitaMag_descrizione() {
        return mtbPartitaMag_descrizione;
    }

    public MtbColr setMtbPartitaMag_descrizione(String mtbPartitaMag_descrizione) {
        this.mtbPartitaMag_descrizione = mtbPartitaMag_descrizione;
        return this;
    }







    public String getDataScadPartitaS() {
        return dataScadPartita;
    }

    public Date getDataScadPartitaD() {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        try {
            if(!UtilityString.isNullOrEmpty(getDataScadPartitaS()))
                return sdf.parse(getDataScadPartitaS());
            else return null;
        } catch (Exception ex) {
            UtilityLogger.errorMe(ex);
            return null;
        }
    }

    public MtbColr setDataScadPartita(String dataScadPartita) {
        this.dataScadPartita = dataScadPartita;
        return this;
    }

    public MtbColr setDataScadPartita(Date dataScadPartita) {
        if(dataScadPartita != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            this.dataScadPartita = sdf.format(dataScadPartita);
        } else this.dataScadPartita = null;
        return this;
    }


    public String getDescrizione() {
        return descrizione;
    }

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



    public String getUntMis() {
        return untMis;
    }

    public MtbColr setUntMis(String untMis) {
        this.untMis = untMis;
        return this;
    }


    public MtbAart getMtbAart() {
        return mtbAart;
    }

    public MtbColr setMtbAart(MtbAart mtbAart) {
        this.mtbAart = mtbAart;
        return this;
    }
}
