using System.Text.Json.Serialization; namespace Shared.Models.Templates { public struct SegmentTpl { public List ads { get; private set; } public List skips { get; private set; } public SegmentTpl() { ads = new List(5); skips = new List(5); } public bool IsEmpty => ads.Count == 0 && skips.Count == 0; public void ad(int start, int end) { if (start >= 0 && end >= 0 && end >= start) ads.Add(new SegmentDto(start == 0 ? 1 : start, end)); } public void skip(int start, int end) { if (start >= 0 && end >= 0 && end >= start) skips.Add(new SegmentDto(start == 0 ? 1 : start, end)); } public Dictionary> ToObject() { if (IsEmpty) return null; return new Dictionary>() { ["ad"] = ads, ["skip"] = skips }; } } public readonly struct SegmentDto { public int start { get; } public int end { get; } [JsonConstructor] public SegmentDto(int start, int end) { this.start = start; this.end = end; } } }