package com.google.launchpod.data;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.text.SimpleDateFormat;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

import org.joda.time.DateTimeUtils;

@JacksonXmlRootElement(localName = "item")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Item {

  @JacksonXmlProperty
  @JsonProperty("title")
  @JsonInclude(JsonInclude.Include.NON_EMPTY)
  private String title;

  @JacksonXmlProperty
  @JsonProperty("link")
  @JsonInclude(JsonInclude.Include.NON_EMPTY)
  private String link;

  @JacksonXmlProperty
  @JsonProperty("description")
  @JsonInclude(JsonInclude.Include.NON_EMPTY)
  private String description;

  @JacksonXmlProperty
  @JsonProperty("pubDate")
  @JsonInclude(JsonInclude.Include.NON_EMPTY)
  private String pubDate;

  private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS z");

  /**
   * constructor generated for serialization/deserialization. Ensures that a
   * constructor is being read for object conversion
   */
  public Item() {
  }

  public Item(String podcastTitle, String podcastDescription, String language, String email, String mp3Link) {
    this.title = podcastTitle;
    this.description = podcastDescription;
    this.link = mp3Link;
    this.pubDate = DATE_FORMATTER.format(DateTimeUtils.currentTimeMillis());
  }

  public void setTitle(String newTitle) {
    this.title = newTitle;
  }

  public void setDescription(String newDescription) {
    this.description = newDescription;
  }

  public String getTitle() {
    return this.title;
  }

  public String getDescription() {
    return this.description;
  }
}

@@ -909,16 +909,258 @@
 ption;%0A%0A
+  @JacksonXmlProperty%0A  @JsonProperty(%22language%22)%0A  @JsonInclude(JsonInclude.Include.NON_EMPTY)%0A  private String language;%0A%0A  @JacksonXmlProperty%0A  @JsonProperty(%22email%22)%0A  @JsonInclude(JsonInclude.Include.NON_EMPTY)%0A  private String email;%0A%0A
   @Jacks
@@ -1196,24 +1196,24 @@
 (%22pubDate%22)%0A
-
   @JsonInclu
@@ -1732,16 +1732,70 @@
 iption;%0A
+    this.language = language;%0A    this.email = email;%0A
     this
@@ -2190,10 +2190,9 @@
 on;%0A  %7D%0A
+
 %7D
-%0A

fix bug where Translation would generate another empty item when deserializing.