package tv.pluto.mongo.entities.episodes;

import com.google.gson.annotations.JsonAdapter;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.bson.BsonType;
import org.bson.codecs.pojo.annotations.BsonRepresentation;
import tv.pluto.mongo.entities.clips.Cc;
import tv.pluto.mongo.entities.clips.DistributeAs;
import tv.pluto.mongo.entities.clips.Markup;
import tv.pluto.mongo.entities.clips.Thumbnail;
import tv.pluto.mongo.entities.clips.TimedText;
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.Fragment;
import tv.pluto.mongo.entities.common.Image;
import tv.pluto.mongo.entities.common.Origin;
import tv.pluto.mongo.entities.common.Source;
import tv.pluto.mongo.utils.json.LocalDateTimeAdapter;

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

  private String name = "";

  @BsonRepresentation(BsonType.OBJECT_ID)
  private String partner;

  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(LocalDateTimeAdapter.class)
  private LocalDateTime uploaded;

  @JsonAdapter(LocalDateTimeAdapter.class)
  private LocalDateTime updated;

  // TODO bug https://plutotv.atlassian.net/browse/ARCH-1799
  //    private tv.pluto.mongo.entities.common.Meta meta = new Meta();
  private Boolean flagged;
  private Boolean captions_required;
  private String captioned = "";
  private List<Cc> cc = Collections.emptyList();
  private String copyright;
  private String language;
  private String ratingReason;

  @JsonAdapter(LocalDateTimeAdapter.class)
  private LocalDateTime 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(LocalDateTimeAdapter.class)
  private LocalDateTime 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;
  private String contentStatus;
  private List<String> regionFilter = Collections.emptyList();
  private AvailabilityWindows availabilityWindows = new AvailabilityWindows();
  private String encodingProfile;
  private String contentUUID;

  List<Markup> markup = Collections.emptyList();
  List<TimedText> timedText = Collections.emptyList();

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

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

  public Boolean getCaptionsRequired() {
    return captions_required != null && captions_required;
  }
}
