using XF.Domain.Entities;
using XF.Domain.Repository;

namespace Hotline.CallCenter.BlackLists;

/// <summary>
/// 黑名单
/// </summary>
public class Blacklist : CreationSoftDeleteEntity
{
    private static readonly string _blacklistPrefix = "blacklist";
    
    /// <summary>
    /// 电话号码
    /// </summary>
    public string PhoneNo { get; set; }

    /// <summary>
    /// 时长（秒）
    /// </summary>
    public double Duration { get; set; }

    /// <summary>
    /// 过期时间(冗余)
    /// </summary>
    public DateTime Expired { get; set; }

    public void InitExpired() => Expired = DateTime.Now.AddSeconds(Duration);

    public static string GetKey(string phone) => $"{_blacklistPrefix}&{phone}";
    
    public static string GetPhone(string key) => key.Split('&', StringSplitOptions.RemoveEmptyEntries).Last();
}