using Febe.Core.Abstractions; namespace Febe.Core.Domain; /// An hourly and daily budget for one action category. public sealed record Budget(int PerHour, int PerDay); /// /// Values of a caution profile (spec §7.5). These are cautious starting estimates, not official limits /// and not measurements: the interface must say so. /// public sealed record CautionProfile { public required CautionProfileKind Kind { get; init; } /// Start of the daily active window (local time). public required TimeOnly WindowStart { get; init; } /// End of the daily active window (local time); may be after midnight (e.g. 00:30). public required TimeOnly WindowEnd { get; init; } /// Random daily shift applied to start and end, ± this amount. public required TimeSpan WindowJitter { get; init; } public required TimeSpan SessionMin { get; init; } public required TimeSpan SessionMax { get; init; } public required TimeSpan PauseMin { get; init; } public required TimeSpan PauseMax { get; init; } /// Budgets per category, excluding . public required IReadOnlyDictionary Budgets { get; init; } /// Daily download budget in bytes. public required long DataPerDayBytes { get; init; } /// Default per-account backfill limit (posts per day). public required int BackfillPostsPerAccountPerDay { get; init; } /// Gradual start: days to go from half to full budgets. public required int RampUpDays { get; init; } /// Active weekdays (all by default). public IReadOnlySet ActiveDays { get; init; } = new HashSet(Enum.GetValues()); public bool GradualStart { get; init; } = true; public GesturePace Pace { get; init; } = GesturePace.Natural; private const long GB = 1024L * 1024 * 1024; public static CautionProfile Prudent { get; } = new() { Kind = CautionProfileKind.Prudent, WindowStart = new TimeOnly(7, 30), WindowEnd = new TimeOnly(23, 30), WindowJitter = TimeSpan.FromMinutes(40), SessionMin = TimeSpan.FromMinutes(2), SessionMax = TimeSpan.FromMinutes(10), PauseMin = TimeSpan.FromMinutes(20), PauseMax = TimeSpan.FromMinutes(90), Budgets = new Dictionary { [ActionKind.Home] = new(4, 30), [ActionKind.ProfileOpen] = new(12, 100), [ActionKind.StoryView] = new(50, 300), [ActionKind.BackfillPage] = new(20, 100), [ActionKind.SinglePost] = new(10, 60), [ActionKind.FollowingListPage] = new(15, 60), [ActionKind.ProfileSearch] = new(240, 1200), }, DataPerDayBytes = 4 * GB, BackfillPostsPerAccountPerDay = 300, RampUpDays = 7, }; public static CautionProfile Balanced { get; } = new() { Kind = CautionProfileKind.Balanced, WindowStart = new TimeOnly(7, 0), WindowEnd = new TimeOnly(0, 0), WindowJitter = TimeSpan.FromMinutes(30), SessionMin = TimeSpan.FromMinutes(3), SessionMax = TimeSpan.FromMinutes(14), PauseMin = TimeSpan.FromMinutes(12), PauseMax = TimeSpan.FromMinutes(60), Budgets = new Dictionary { [ActionKind.Home] = new(5, 45), [ActionKind.ProfileOpen] = new(20, 180), [ActionKind.StoryView] = new(80, 500), [ActionKind.BackfillPage] = new(30, 180), [ActionKind.SinglePost] = new(15, 100), [ActionKind.FollowingListPage] = new(20, 90), [ActionKind.ProfileSearch] = new(300, 1500), }, DataPerDayBytes = 8 * GB, BackfillPostsPerAccountPerDay = 500, RampUpDays = 5, }; public static CautionProfile Fast { get; } = new() { Kind = CautionProfileKind.Fast, WindowStart = new TimeOnly(6, 30), WindowEnd = new TimeOnly(0, 30), WindowJitter = TimeSpan.FromMinutes(30), SessionMin = TimeSpan.FromMinutes(4), SessionMax = TimeSpan.FromMinutes(18), PauseMin = TimeSpan.FromMinutes(8), PauseMax = TimeSpan.FromMinutes(40), Budgets = new Dictionary { [ActionKind.Home] = new(6, 60), [ActionKind.ProfileOpen] = new(30, 300), [ActionKind.StoryView] = new(120, 800), [ActionKind.BackfillPage] = new(45, 300), [ActionKind.SinglePost] = new(20, 160), [ActionKind.FollowingListPage] = new(30, 150), [ActionKind.ProfileSearch] = new(360, 1800), }, DataPerDayBytes = 16 * GB, BackfillPostsPerAccountPerDay = 800, RampUpDays = 3, }; public static CautionProfile For(CautionProfileKind kind) => kind switch { CautionProfileKind.Prudent => Prudent, CautionProfileKind.Balanced => Balanced, CautionProfileKind.Fast => Fast, _ => throw new ArgumentOutOfRangeException(nameof(kind), kind, "Custom profiles are stored values, not presets."), }; /// Limits enforced by the interface (spec §7.5): minimum pause 5 min, session ≤ 30 min, window ≤ 20 h, no budget above twice «Rapido». public static class Limits { public static readonly TimeSpan MinPause = TimeSpan.FromMinutes(5); public static readonly TimeSpan MaxSession = TimeSpan.FromMinutes(30); public static readonly TimeSpan MaxWindow = TimeSpan.FromHours(20); public static Budget MaxBudget(ActionKind kind) => new(Fast.Budgets[kind].PerHour * 2, Fast.Budgets[kind].PerDay * 2); public static long MaxDataPerDayBytes => Fast.DataPerDayBytes * 2; } }