< Summary

Information
Class: OzonDomains.Models.AssemblyListAccessKey
Assembly: OzonDomains
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonDomains/Models/AssemblyListAccessKey.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 31
Coverable lines: 31
Total lines: 75
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 20
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonDomains/Models/AssemblyListAccessKey.cs

#LineLine coverage
 1using System.ComponentModel.DataAnnotations;
 2using System.ComponentModel.DataAnnotations.Schema;
 3using System.Text.Json;
 4
 5namespace OzonDomains.Models;
 6
 7public class AssemblyListAccessKey
 8{
 09    public long Id { get; set; }
 10
 11    [MaxLength(64)]
 012    public string AccessKey { get; set; } = null!;
 13
 014    public bool IsActive { get; set; } = true;
 15
 016    public DateTime? ExpiresAt { get; set; }
 17
 18    [MaxLength(500)]
 019    public string? Description { get; set; }
 20
 021    public string AllowedOzonClientIds { get; set; } = "[]";
 22
 023    public string AllowedStatuses { get; set; } = "[]";
 24
 025    public string AllowedWarehouses { get; set; } = "[]";
 26
 027    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
 28
 29    /// <summary>Смещение в днях от «сегодня» для даты С (например −7 = неделя назад).</summary>
 030    public int PeriodFromOffsetDays { get; set; } = -7;
 31
 32    /// <summary>Смещение в днях от «сегодня» для даты По (например 1 = завтра).</summary>
 033    public int PeriodToOffsetDays { get; set; } = 1;
 34
 35    [NotMapped]
 36    public List<int> AllowedClientIdList =>
 037        JsonSerializer.Deserialize<List<int>>(AllowedOzonClientIds) ?? new();
 38
 39    [NotMapped]
 40    public List<string> AllowedStatusList =>
 041        JsonSerializer.Deserialize<List<string>>(AllowedStatuses) ?? new();
 42
 43    [NotMapped]
 44    public List<string> AllowedWarehouseList =>
 045        JsonSerializer.Deserialize<List<string>>(AllowedWarehouses) ?? new();
 46
 47    [NotMapped]
 048    public bool IsExpired => ExpiresAt.HasValue && ExpiresAt.Value < DateTime.UtcNow;
 49
 50    public (DateTime From, DateTime To) ResolvePeriod(DateTime? referenceDate = null)
 51    {
 052        var today = (referenceDate ?? DateTime.Today).Date;
 053        return (today.AddDays(PeriodFromOffsetDays), today.AddDays(PeriodToOffsetDays));
 54    }
 55
 56    public string FormatPeriodOffsetLabel()
 57    {
 058        static string DayWord(int n) => Math.Abs(n) switch
 059        {
 060            1 => "день",
 061            >= 2 and <= 4 => "дня",
 062            _ => "дней",
 063        };
 64
 065        static string OffsetLabel(int offset) => offset switch
 066        {
 067            0 => "сегодня",
 068            -1 => "вчера",
 069            1 => "завтра",
 070            _ => $"{offset} {DayWord(offset)} от сегодня",
 071        };
 72
 073        return $"{OffsetLabel(PeriodFromOffsetDays)} – {OffsetLabel(PeriodToOffsetDays)}";
 74    }
 75}