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.BsonIgnore;
import org.bson.codecs.pojo.annotations.BsonRepresentation;
import tv.pluto.mongo.entities.common.AvailabilityWindows;
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;

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

  @JsonAdapter(LocalDateTimeAdapter.class)
  private LocalDateTime createdAt;

  @JsonAdapter(LocalDateTimeAdapter.class)
  private LocalDateTime updatedAt;

  private String name = "";
  private String displayName = "";
  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;
  @BsonIgnore private Series series;
  private Integer season;
  private Integer duration;
  private Integer allotment;
  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;

  @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;
  @BsonIgnore private Episodes parent;
  private List<ContentPopulated> content = Collections.emptyList();
  private List<SourcePopulated> sources = Collections.emptyList();
  private List<BackupsPopulated> backups = Collections.emptyList();
  @BsonIgnore private List<Channel> channels = Collections.emptyList();
  private Image thumbnail = new Image();
  private Image featuredImage = new Image();
  private Image partnerLogo = new Image();
  private Image poster = 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 Boolean flagged;
  private DistributeAs distributeAs = new DistributeAs();
  private PlaybackRestrictions playbackRestrictions = new PlaybackRestrictions();
  @BsonIgnore private List<VodCategoryEntry> 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
  private List<String> regionFilter = Collections.emptyList();
  private Boolean dashEnabled;
  @BsonIgnore private List<AgeRange> ageRange = Collections.emptyList();
  private String contentUUID = "";

  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 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 getTmsid() {
    return tmsid == null ? "" : tmsid;
  }

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

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

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

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

  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 getAdPodsDuration() {
    return adPodsDuration == null ? 0 : adPodsDuration;
  }

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

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

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

  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 Boolean getAdPodsVerified() {
    return adPodsVerified != null && adPodsVerified;
  }

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