package com.camilstaps.taize;

import com.camilstaps.common.Date;
import com.camilstaps.common.DatedString;

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

/**
 * Created by camilstaps on 15-4-15.
 */
public class Podcast extends DatedString implements Comparable<Podcast> {

    public Podcast(Date date, String title, String url) throws JSONException {
        super(date, (new JSONObject()).put("title", title).put("url", url).toString());
    }

    private JSONObject getJSONObject() {
        try {
            return new JSONObject(getString());
        } catch (JSONException e) {
            return null;
        }
    }

    public String getTitle() {
        try {
            return getJSONObject().getString("title");
        } catch (JSONException e) {
            return "";
        }
    }

    public String getUrl() {
        try {
            return getJSONObject().getString("url");
        } catch (JSONException e) {
            return "";
        }
    }

    @Override
    public int compareTo(Podcast another) {
        return getDate().compareTo(another.getDate());
    }
}