using System;
using System.Globalization;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
namespace IntroSkipper.Data;
///
/// Result of fingerprinting and analyzing two episodes in a season.
/// All times are measured in seconds relative to the beginning of the media file.
///
[DataContract(Namespace = "http://schemas.datacontract.org/2004/07/ConfusedPolarBear.Plugin.IntroSkipper.Segment")]
public class Segment
{
///
/// Initializes a new instance of the class.
///
/// Episode.
/// Introduction time range.
public Segment(Guid episode, TimeRange segment)
{
EpisodeId = episode;
Start = segment.Start;
End = segment.End;
}
///
/// Initializes a new instance of the class.
///
/// Episode.
public Segment(Guid episode)
{
EpisodeId = episode;
Start = 0;
End = 0;
}
///
/// Initializes a new instance of the class.
///
/// intro.
public Segment(Segment intro)
{
EpisodeId = intro.EpisodeId;
Start = intro.Start;
End = intro.End;
}
///
/// Initializes a new instance of the class.
///
/// intro.
public Segment(Intro intro)
{
EpisodeId = intro.EpisodeId;
Start = intro.IntroStart;
End = intro.IntroEnd;
}
///
/// Initializes a new instance of the class.
///
public Segment()
{
}
///
/// Gets or sets the Episode ID.
///
[DataMember]
public Guid EpisodeId { get; set; }
///
/// Gets or sets the introduction sequence start time.
///
[DataMember]
public double Start { get; set; }
///
/// Gets or sets the introduction sequence end time.
///
[DataMember]
public double End { get; set; }
///
/// Gets a value indicating whether this introduction is valid or not.
/// Invalid results must not be returned through the API.
///
public bool Valid => End > 0;
///
/// Gets the duration of this intro.
///
[JsonIgnore]
public double Duration => End - Start;
}