package com.albertattard.m2m.server;

import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Item {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	@Persistent
	private String name;
	@Persistent
	private Set<Key> categories;

	public Set<Key> getCategories() {
		return categories;
	}

	public void setCategories(Set<Key> categories) {
		this.categories = categories;
	}

	public void addCategory(Key category) {
		if (categories == null) {
			categories = new HashSet<Key>();
		}
		categories.add(category);
	}

	public Key getKey() {
		return key;
	}

	public String getName() {
		return name;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Item [key=" + key + ", name=" + name + ", categories="
				+ categories + "]";
	}

}
