package org.foxarmy.barcodescannerforemployees.dataclasses

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

class AbstractProduct() : Parcelable {
    var id: Int = 0
    var barcode: String = ""
    var name: String = ""
    var netWeight: Double = 0.0
    var imageHash: String = ""
    var category: Int = 0
    var unit: Int = 0

    constructor(id: Int, barcode: String, name: String, netWeight: Double, imageHash: String, category: Int, unit: Int) : this() {
        this.id = id
        this.barcode = barcode
        this.name = name
        this.netWeight = netWeight
        this.imageHash = imageHash
        this.category = category
        this.unit = unit
    }

    constructor(parcel: Parcel) : this() {
        id = parcel.readInt()
        barcode = parcel.readString()!!
        name = parcel.readString()!!
        netWeight = parcel.readDouble()
        imageHash = parcel.readString()!!
        category = parcel.readInt()
        unit = parcel.readInt()
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeInt(id)
        parcel.writeString(barcode)
        parcel.writeString(name)
        parcel.writeDouble(netWeight)
        parcel.writeString(imageHash)
        parcel.writeInt(category)
        parcel.writeInt(unit)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<AbstractProduct> {
        override fun createFromParcel(parcel: Parcel): AbstractProduct {
            return AbstractProduct(parcel)
        }

        override fun newArray(size: Int): Array<AbstractProduct?> {
            return arrayOfNulls(size)
        }
    }
}