package kr.co.icontrols.iotplatform.DataClass;

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

import java.io.Serializable;

public class DeviceInfo implements Serializable, Parcelable {
    public String deviceId;
    public String deviceType;
    public String friendlyName;
    public String sharedFriendlyName;
    public String dgroupId;
    public String dgroupName;
    public String ownerId;
    public int isSelected;
    public int rank;
    public int groupRank;

    public DeviceInfo() {
        isSelected = 0;
    }

    public DeviceInfo(
            String deviceId,
            String deviceType,
            String friendlyName,
            String sharedFriendlyName,
            String dgroupId,
            String dgroupName,
            String ownerId,
            int rank,
            int groupRank) {
        this.deviceId = deviceId;
        this.deviceType = deviceType;
        this.friendlyName = friendlyName;
        this.sharedFriendlyName = sharedFriendlyName;
        this.dgroupId = dgroupId;
        this.dgroupName = dgroupName;
        this.ownerId = ownerId;
        this.rank = rank;
        this.groupRank = groupRank;
        this.isSelected = 0;
    }

    public DeviceInfo(DeviceInfo item) {
        this.deviceId = item.deviceId;
        this.deviceType = item.deviceType;
        this.friendlyName = item.friendlyName;
        this.sharedFriendlyName = item.sharedFriendlyName;
        this.dgroupId = item.dgroupId;
        this.dgroupName = item.dgroupName;
        this.ownerId = item.ownerId;
        this.rank = item.rank;
        this.groupRank = item.groupRank;
        this.isSelected = item.isSelected;
    }

    public DeviceInfo(Parcel item) {
        this.deviceId = item.readString();
        this.deviceType = item.readString();
        this.friendlyName = item.readString();
        this.sharedFriendlyName = item.readString();
        this.dgroupId = item.readString();
        this.dgroupName = item.readString();
        this.ownerId = item.readString();
        this.rank = item.readInt();
        this.groupRank = item.readInt();
        this.isSelected = item.readInt();
    }

    public boolean isSelected() {
        return isSelected != 0;
    }
    
    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.deviceId);
        dest.writeString(this.deviceType);
        dest.writeString(this.friendlyName);
        dest.writeString(this.sharedFriendlyName);
        dest.writeString(this.dgroupId);
        dest.writeString(this.dgroupName);
        dest.writeString(this.ownerId);
        dest.writeInt(this.rank);
        dest.writeInt(this.groupRank);
        dest.writeInt(this.isSelected);
    }

    @SuppressWarnings("rawtypes")
    public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {

        @Override
        public DeviceInfo createFromParcel(Parcel in) {
            return new DeviceInfo(in);
        }

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