/*
 * (c) 2020 Pluto Inc.
 */

package tv.pluto.mongo.entities.episodes;

import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.BsonType;
import org.bson.codecs.pojo.annotations.BsonRepresentation;
import org.bson.types.ObjectId;
import tv.pluto.mongo.entities.common.AvailabilityWindows;
import tv.pluto.mongo.entities.common.Backups;
import tv.pluto.mongo.entities.common.Content;
import tv.pluto.mongo.entities.common.DistributeAs;
import tv.pluto.mongo.entities.common.Image;
import tv.pluto.mongo.entities.common.NextTimeline;
import tv.pluto.mongo.entities.common.PlaybackRestrictions;
import tv.pluto.mongo.utils.json.DateAdapter;
import tv.pluto.mongo.utils.json.LocalDateTimeAdapter;
import tv.pluto.mongo.utils.json.ObjectIdsAdapter;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Episodes {
  @BsonRepresentation(BsonType.OBJECT_ID)
  private String id;

  @JsonAdapter(DateAdapter.class)
  private Date createdAt;

  @JsonAdapter(LocalDateTimeAdapter.class)
  private LocalDateTime updatedAt;

  private Integer allotment;
  private String name = "";
  private String displayName = "";

  @SerializedName(value = "displayOnGuide", alternate = "display_on_guide")
  private String displayOnGuide = "";

  private Boolean adFree;
  private Boolean adPodsVerified;

  @BsonRepresentation(BsonType.OBJECT_ID)
  private String author;

  private String slug = "";
  private String uid = "";
  private Integer number;

  @BsonRepresentation(BsonType.OBJECT_ID)
  private String series;

  private Integer season;
  private Integer duration;
  //    TODO investigate type issue
  private Integer adPodsDuration;
  private String description = "";
  private String summary = "";
  private String notes = "";
  private String category = "";
  private String subCategory = "";
  private String genre = "";
  private String subGenre = "";
  private List<String> tags = Collections.emptyList();
  private Boolean published;
  private String status = "";
  private Boolean liveBroadcast;
  private Boolean highlight;

  @JsonAdapter(DateAdapter.class)
  private Date premiere;

  @JsonAdapter(DateAdapter.class)
  private Date firstAired;

  @JsonAdapter(DateAdapter.class)
  private Date lastAired;

  private NextTimeline nextTimeline = new NextTimeline();
  private Boolean derivative;
  private Boolean is_feed;
  private List<String> feeds = Collections.emptyList();
  private Boolean featured;

  @BsonRepresentation(BsonType.OBJECT_ID)
  private String parent;

  private List<Content> content = Collections.emptyList();
  private List<Source> sources = Collections.emptyList();
  private List<Backups> backups = Collections.emptyList();

  @JsonAdapter(ObjectIdsAdapter.class)
  private List<ObjectId> channels = Collections.emptyList();

  private Image thumbnail = new Image();
  private Image featuredImage = new Image();
  private Image partnerLogo = new Image();
  private Image poster = new Image();
  private Image thumbnailAlt = new Image();
  private Image featuredImageAlt = new Image();
  private Image logoAlt = new Image();
  private Image solidLogoPNGAlt = new Image();
  private Image colorLogoPNGAlt = new Image();
  private Image solidLogoSVGAlt = new Image();
  private Image colorLogoSVGAlt = new Image();

  @SerializedName("screenshot169")
  private Image screenshot16_9 = new Image();

  @SerializedName("screenshot43")
  private Image screenshot4_3 = new Image();

  // TODO bug https://plutotv.atlassian.net/browse/ARCH-1799
  //    private Meta meta = new Meta();
  private List<CustomReferences> customReferences = Collections.emptyList();
  private List<String> ratingDescriptors = Collections.emptyList();
  private Boolean flagged;
  private DistributeAs distributeAs = new DistributeAs();
  private PlaybackRestrictions playbackRestrictions = new PlaybackRestrictions();

  @JsonAdapter(ObjectIdsAdapter.class)
  private List<ObjectId> vodCategoryEntries = Collections.emptyList();

  private Boolean plutoTvOO;
  private String tmsid = "";
  private String activeRegion = ""; // not in schema
  private AvailabilityWindows availabilityWindows = new AvailabilityWindows(); // not in schema
  private String metadataLanguage = ""; // not in schema
  private String rating = ""; // not in schema
  // TODO check fields with protofile
  private List<String> regionFilter = Collections.emptyList();
  private Boolean dashEnabled;
  private Boolean promotionalAdpods;

  @JsonAdapter(ObjectIdsAdapter.class)
  private List<ObjectId> ageRange = Collections.emptyList();

  private String contentUUID = "";

  @SerializedName(value = "poster16_9", alternate = "poster169")
  private Image poster16_9;

  public Boolean getAdFree() {
    return adFree != null && adFree;
  }

  public Boolean getPromotionalAdpods() {
    return promotionalAdpods != null && promotionalAdpods;
  }

  public Boolean getAdPodsVerified() {
    return adPodsVerified != null && adPodsVerified;
  }

  public Integer getNumber() {
    return number == null ? 0 : number;
  }

  public Integer getSeason() {
    return season == null ? 0 : season;
  }

  public Integer getDuration() {
    return duration == null ? 0 : duration;
  }

  public Integer getAllotment() {
    return allotment == null ? 0 : allotment;
  }

  public Integer getAdPodsDuration() {
    return adPodsDuration == null ? 0 : adPodsDuration;
  }

  public Boolean getPublished() {
    return published != null && published;
  }

  public Boolean getLiveBroadcast() {
    return liveBroadcast != null && liveBroadcast;
  }

  public Boolean getHighlight() {
    return highlight != null && highlight;
  }

  public Boolean getDerivative() {
    return derivative != null && derivative;
  }

  public Boolean getIsFeed() {
    return is_feed != null && is_feed;
  }

  public Boolean getFeatured() {
    return featured != null && featured;
  }

  public Boolean getFlagged() {
    return flagged != null && flagged;
  }

  public Boolean getPlutoTvOO() {
    return plutoTvOO != null && plutoTvOO;
  }

  public Boolean getDashEnabled() {
    return dashEnabled != null && dashEnabled;
  }

  public String getName() {
    return name == null ? "" : name;
  }

  public String getDisplayName() {
    return displayName == null ? "" : displayName;
  }

  public String getDisplayOnGuide() {
    return displayOnGuide == null ? "" : displayOnGuide;
  }

  public String getAuthor() {
    return author == null ? "" : author;
  }

  public String getSlug() {
    return slug == null ? "" : slug;
  }

  public String getUid() {
    return uid == null ? "" : uid;
  }

  public String getSeries() {
    return series == null ? "" : series;
  }

  public String getDescription() {
    return description == null ? "" : description;
  }

  public String getSummary() {
    return summary == null ? "" : summary;
  }

  public String getNotes() {
    return notes == null ? "" : notes;
  }

  public String getCategory() {
    return category == null ? "" : category;
  }

  public String getSubCategory() {
    return subCategory == null ? "" : subCategory;
  }

  public String getGenre() {
    return genre == null ? "" : genre;
  }

  public String getSubGenre() {
    return subGenre == null ? "" : subGenre;
  }

  public String getStatus() {
    return status == null ? "" : status;
  }

  public String getParent() {
    return parent == null ? "" : parent;
  }

  public String getTmsid() {
    return tmsid == null ? "" : tmsid;
  }

  public String getActiveRegion() {
    return activeRegion == null ? "" : activeRegion;
  }

  public String getRating() {
    return rating == null ? "" : rating;
  }

  public String getContentUUID() {
    return contentUUID == null ? "" : contentUUID;
  }

  public String getMetadataLanguage() {
    return metadataLanguage == null ? "" : metadataLanguage;
  }

  public Image getScreenshot169() {
    return screenshot16_9;
  }

  public Image getScreenshot43() {
    return screenshot4_3;
  }
}
