package com.hikapro.backpack.model.entities;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by tariel on 02/04/16.
 */
public class Item implements Comparable<Item>, Serializable {

    @SerializedName("id")
    @Expose
    private int id;
    @SerializedName("name")
    @Expose
    private String name;
    @SerializedName("item_category_id")
    @Expose
    private int category;
    @SerializedName("description")
    @Expose
    private String description;
    @SerializedName("buy_urls")
    @Expose
    private List<String> buyUrls = new ArrayList<String>();
    @SerializedName("photo")
    @Expose
    private String photoUrl;
    @SerializedName("photo_thumb")
    @Expose
    private String photoThumbUrl;

    private String photoLocal;

    private boolean userDefined;

    private boolean pendingRemoval;

    private boolean packed;

    public boolean InList;

    public Item() {
    }

    public Item(String name, int category) {
        this.id = -1;
        this.name = name;
        this.category = category;
    }

    public Item(int id, String name, int category, String description, List<String> buyUrls,
                String photoUrl, String photoThumbUrl) {
        this.id = id;
        this.name = name;
        this.category = category;
        this.description = description;
        this.buyUrls = buyUrls;
        this.photoUrl = photoUrl;
        this.photoThumbUrl = photoThumbUrl;
    }

    public int getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCategory() {
        return category;
    }

    public void setCategory(int category) {
        this.category = category;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<String> getBuyUrls() {
        return buyUrls;
    }

    public void setBuyUrls(List<String> buyUrls) {
        this.buyUrls = buyUrls;
    }

    public String getPhotoUrl() {
        return photoUrl;
    }

    public void setPhotoUrl(String photoUrl) {
        this.photoUrl = photoUrl;
    }

    public String getPhotoThumbUrl() {
        return photoThumbUrl;
    }

    public void setPhotoThumbUrl(String photoThumbUrl) {
        this.photoThumbUrl = photoThumbUrl;
    }

    public String getPhotoLocal() {
        return photoLocal;
    }

    public void setPhotoLocal(String photoLocal) {
        this.photoLocal = photoLocal;
    }

    public boolean isUserDefined() {
        return userDefined;
    }

    public void setUserDefined(boolean userDefined) {
        this.userDefined = userDefined;
    }

    public boolean isPendingRemoval() {
        return pendingRemoval;
    }

    public void setPendingRemoval(boolean pendingRemoval) {
        this.pendingRemoval = pendingRemoval;
    }

    public boolean isPacked() {
        return packed;
    }

    public void setPacked(boolean packed) {
        this.packed = packed;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        return result;
    }

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

        Item that = (Item) o;

        if (id != that.id)
            return false;
        return true;

    }

    @Override
    public int compareTo(Item another) {
        int cmp = Integer.valueOf(category).compareTo(Integer.valueOf(another.category));
        if (cmp != 0)
            return cmp;
        else {
            cmp = Boolean.valueOf(pendingRemoval).compareTo(Boolean.valueOf(another.pendingRemoval));
            return (cmp != 0 ? cmp : name.compareTo(another.name));
        }
    }
}
