/*
 * (c) 2020 Pluto Inc.
 */
package tv.pluto.mongo.entities.clips;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.gson.annotations.JsonAdapter;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.BsonType;
import org.bson.codecs.pojo.annotations.BsonRepresentation;
import tv.pluto.mongo.entities.common.Advertising;
import tv.pluto.mongo.entities.common.Author;
import tv.pluto.mongo.entities.common.AvailabilityWindows;
import tv.pluto.mongo.entities.common.DiscreteAudio;
import tv.pluto.mongo.entities.common.Fragment;
import tv.pluto.mongo.entities.common.Image;
import tv.pluto.mongo.entities.common.Meta;
import tv.pluto.mongo.entities.common.Origin;
import tv.pluto.mongo.entities.common.Source;
import tv.pluto.mongo.entities.common.Transcode;
import tv.pluto.mongo.utils.json.DateAdapter;
import tv.pluto.mongo.utils.json.LocalDateTimeAdapter;
import tv.pluto.mongo.utils.json.MapDataDeserializer;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Clips {
  @BsonRepresentation(BsonType.OBJECT_ID)
  private String id;

  @BsonRepresentation(BsonType.OBJECT_ID)
  private String partner;

  @JsonAdapter(MapDataDeserializer.class)
  private Map<String, DistributeAs> languageOverrides = new HashMap<>();

  @JsonAdapter(MapDataDeserializer.class)
  private Map<String, RegionOverrides> regionOverrides = new HashMap<>();

  private TranscodeObject transcode = new TranscodeObject();
  private IngestionStatus ingestionStatus = new IngestionStatus();

  private String name;
  private String description;
  private Author author = new Author();
  private Advertising advertising = new Advertising();
  private Image featuredImage = new Image();
  private String thumbnail;
  private List<Thumbnail> thumbnails = Collections.emptyList();
  private String plutoAvailsId;
  private Boolean published;
  private Boolean liveBroadcast;
  private Boolean promotional;
  private String provider;
  private String code;
  private String partnerCode;
  private String internalCode;
  private String md5;
  private String url;
  private List<Fragment> fragments = Collections.emptyList();
  private Double inPoint;
  private Double outPoint;
  private String type;
  private List<String> tags = Collections.emptyList();
  private Integer score;
  private Integer votes;

  @JsonAdapter(DateAdapter.class)
  private Date uploaded;

  @JsonAdapter(LocalDateTimeAdapter.class)
  private LocalDateTime updated;

  private Meta meta = new Meta();
  private Boolean flagged;
  private Boolean captions_required;
  private Boolean isArchived;
  private String captioned = "";
  private List<Cc> cc = Collections.emptyList();
  private String copyright;
  private String language;
  private String ratingReason;

  @JsonAdapter(DateAdapter.class)
  private Date originalReleaseDate;

  private String genre;
  private String subGenre;
  private String summary;
  private List<Cc> subtitles = Collections.emptyList();
  private List<String> directors = Collections.emptyList();
  private List<String> actors = Collections.emptyList();
  private List<String> writers = Collections.emptyList();
  private List<String> producers = Collections.emptyList();
  private List<Integer> breakpoints = Collections.emptyList();
  private List<String> breakpointsSMPTE = Collections.emptyList();
  private List<String> breakpointsIngestion = Collections.emptyList();
  private DistributeAs distributeAs;
  private String programmingType;
  private String color;
  private String category;
  private String adSparxStreamId;
  private Double framerate;
  private Double ffprobeFramerate;
  private Double feedFramerate;
  private String tmsid;

  @JsonAdapter(DateAdapter.class)
  private Date createdAt;

  @JsonAdapter(LocalDateTimeAdapter.class)
  private LocalDateTime updatedAt;

  private List<Source> sources = Collections.emptyList();
  private String rating;
  private Double duration;
  private Origin origin = new Origin();
  private List<Transcode> transcodes = Collections.emptyList();
  private String activeRegion;

  // not found in schema, but found in DB;
  private String contentStatus;
  private List<String> regionFilter = Collections.emptyList();
  private AvailabilityWindows availabilityWindows = new AvailabilityWindows();
  private String encodingProfile;
  private String libVersion;
  private String transcoderVersion;
  private EncryptionParams encryptionParams = new EncryptionParams();
  private Highlight highlight = new Highlight();
  private String contentUUID;
  private List<Markup> markups = Collections.emptyList();
  private List<TimedText> timedText = Collections.emptyList();
  private List<DiscreteAudio> discreteAudio = Collections.emptyList();
  private List<String> productionCompany = Collections.emptyList();
  private List<String> productionCountries = Collections.emptyList();
  private Integer productionYear;

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

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

  public Boolean getPromotional() {
    return promotional != null && promotional;
  }

  public Double getInPoint() {
    return inPoint == null ? 0 : inPoint;
  }

  public Double getOutPoint() {
    return outPoint == null ? 0 : outPoint;
  }

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

  public Integer getScore() {
    return score == null ? 0 : score;
  }

  public Integer getVotes() {
    return votes == null ? 0 : votes;
  }

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

  public Boolean getIsArchived() {
    return isArchived != null && isArchived;
  }

  public Double getFramerate() {
    return framerate == null ? 0 : framerate;
  }

  public Double getFfprobeFramerate() {
    return ffprobeFramerate == null ? 0 : ffprobeFramerate;
  }

  public Double getFeedFramerate() {
    return feedFramerate == null ? 0 : feedFramerate;
  }

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

  public String getPartner() {
    return partner == null ? "" : partner;
  }

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

  public String getThumbnail() {
    return thumbnail == null ? "" : thumbnail;
  }

  public String getPlutoAvailsId() {
    return plutoAvailsId == null ? "" : plutoAvailsId;
  }

  public String getProvider() {
    return provider == null ? "" : provider;
  }

  public String getCode() {
    return code == null ? "" : code;
  }

  public String getPartnerCode() {
    return partnerCode == null ? "" : partnerCode;
  }

  public String getInternalCode() {
    return internalCode == null ? "" : internalCode;
  }

  public String getMd5() {
    return md5 == null ? "" : md5;
  }

  public String getUrl() {
    return url == null ? "" : url;
  }

  public String getType() {
    return type == null ? "" : type;
  }

  public String getCaptioned() {
    return captioned == null ? "" : captioned;
  }

  public String getCopyright() {
    return copyright == null ? "" : copyright;
  }

  public String getLanguage() {
    return language == null ? "" : language;
  }

  public String getRatingReason() {
    return ratingReason == null ? "" : ratingReason;
  }

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

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

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

  public String getColor() {
    return color == null ? "" : color;
  }

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

  public String getAdSparxStreamId() {
    return adSparxStreamId == null ? "" : adSparxStreamId;
  }

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

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

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

  public String getContentStatus() {
    return contentStatus == null ? "" : contentStatus;
  }

  public String getEncodingProfile() {
    return encodingProfile == null ? "" : encodingProfile;
  }

  public String getLibVersion() {
    return libVersion == null ? "" : libVersion;
  }

  public String getTranscoderVersion() {
    return transcoderVersion == null ? "" : transcoderVersion;
  }

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

  public String getProgrammingType() {
    return programmingType == null ? "" : programmingType;
  }

  public int getProductionYear() {
    return productionYear == null ? 0 : productionYear;
  }
}
