package com.dawanda.db;

import com.google.common.base.Preconditions;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;

/**
 * Simple POJO to keep the product attributes fetched from db.
 */
public class Product {
    private final int id;
    private final int sellerId;
    private final int category;
    private final String title;
    private final String description;

    @JsonCreator
    public Product(@JsonProperty("id") int id,
                   @JsonProperty("sellerId") int sellerId,
                   @JsonProperty("category") int category,
                   @JsonProperty("title") String title,
                   @JsonProperty("description") String description) {
        Preconditions.checkNotNull(description);
        Preconditions.checkNotNull(title);
        Preconditions.checkArgument(id > 0);
        Preconditions.checkArgument(category > 0);
        this.id = id;
        this.sellerId = sellerId;
        this.category = category;
        this.title = title;
        this.description = description;
    }

    public int getId() {
        return id;
    }

    public int getSellerId() {
        return sellerId;
    }

    public int getCategory() {
        return category;
    }

    public String getTitle() {
        return title;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return String.format(">> id: %d\n>> category: %d\n>> title: %s\n>> description: %s", id, category, title, description);
    }
}

@@ -22,53 +22,8 @@
 b;%0A%0A
-import com.google.common.base.Preconditions;%0A
 impo
@@ -68,16 +68,16 @@
 reator;%0A
+
 import o
@@ -687,196 +687,8 @@
 ) %7B%0A
-        Preconditions.checkNotNull(description);%0A        Preconditions.checkNotNull(title);%0A        Preconditions.checkArgument(id %3E 0);%0A        Preconditions.checkArgument(category %3E 0);%0A
     
@@ -1221,119 +1221,257 @@
 urn 
-String.format(%22%3E%3E id: %25d%5Cn%3E%3E category: %25d%5Cn%3E%3E title: %25s%5Cn%3E%3E description: %25s%22, id, category, title, description)
+%22Product%7B%22 +%0A                %22id=%22 + id +%0A                %22, category=%22 + category +%0A                %22, title='%22 + title + '%5C'' +%0A                %22, description='%22 + description + '%5C'' +%0A                %22, sellerId=%22 + sellerId +%0A                '%7D'
 ;%0A  

allow empty title or description