package org.plezervikt.netexample.models;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

/**
 * Created by coelho on 2014.10.22..
 */
public class Book implements Serializable {

    private String title;
    private String author;
    private String publisher;
    private int published;

    public Book(String title, String author, String publisher, int published) {
        this.title = title;
        this.author = author;
        this.publisher = publisher;
        this.published = published;
    }

    public String getTitle() {
        return title;
    }

    public String getAuthor() {
        return author;
    }

    public String getPublisher() {
        return publisher;
    }

    public int getPublished() {
        return published;
    }

    public static Book parseFromJSON(JSONObject obj) throws JSONException {
        String title = obj.getString("title");
        String author = obj.getString("author");
        String publisher = obj.getString("publisher");
        int published = obj.getInt("published");
        return new Book(title, author, publisher, published);
    }

    @Override
    public String toString() {
        return "Book{" +
                "title='" + title + '\'' +
                ", author='" + author + '\'' +
                ", publisher='" + publisher + '\'' +
                ", published=" + published +
                '}';
    }
}
