Luski.Net/Luski.net/Structures/Public/SocketCategory.cs

105 lines
3.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JacobTechEncryption.Enums;
2024-08-27 10:57:22 -04:00
using Luski.Shared.PublicServers.V1.Enums;
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
namespace Luski.net.Structures.Public;
public class SocketCategory
{
public PublicServer Server { get; init; } = default!;
public long ID { get; init; }
internal long ParentID { get; set; }
2024-08-27 10:57:22 -04:00
internal RoleOverrideSTC[] RoleOverides { get; set; }
internal UserOverrideSTC[] UserOverides { get; set; }
internal long[] Channels { get; set; }
internal long[] Categories { get; set; }
SocketCategory? RawParent = null;
2024-03-31 23:57:12 -04:00
List<RoleOverride>? RawRoleOverides = null;
2024-03-20 23:18:34 -04:00
List<UserOverride>? RawUserOverides = null;
List<SocketChannel>? RawChan = null;
List<SocketCategory>? RawCat = null;
public async Task<SocketCategory?> GetParent()
{
if (ParentID != -1 && RawParent is null)
{
RawParent = await Server.GetCategory<SocketCategory>(ParentID, CancellationToken.None);
}
return RawParent;
}
public async Task<SocketChannel[]> GetChannels()
{
if (RawChan is null)
{
RawChan = new();
foreach (long chan in Channels)
{
RawChan.Add(await Server.GetChannel<SocketChannel>(chan, CancellationToken.None));
}
}
if (RawChan.Count != Channels.Length)
{
foreach (long chan in Channels)
{
if (RawChan.Any(s => s.ID == chan)) continue;
RawChan.Add(await Server.GetChannel<SocketChannel>(chan, CancellationToken.None));
}
}
return RawChan.ToArray();
}
public async Task<SocketCategory[]> GetCategories()
{
if (RawCat is null)
{
RawCat = new();
foreach (long chan in Categories)
{
RawCat.Add(await Server.GetCategory<SocketCategory>(chan, CancellationToken.None));
}
}
if (RawCat.Count != Channels.Length)
{
foreach (long chan in Categories)
{
if (RawCat.Any(s => s.ID == chan)) continue;
RawCat.Add(await Server.GetCategory<SocketCategory>(chan, CancellationToken.None));
}
}
return RawCat.ToArray();
}
public string Name { get; internal set; }
public string Description { get; internal set; }
2024-03-31 23:57:12 -04:00
public Task<RoleOverride[]> GetRoleOverrides()
{
if (RawRoleOverides is null)
{
RawRoleOverides = new();
}
return Task.FromResult(RawRoleOverides!.ToArray());
}
2024-03-20 23:18:34 -04:00
public Task<UserOverride[]> GetUserOverrides()
{
if (RawUserOverides is null)
{
RawUserOverides = new();
}
return Task.FromResult(RawUserOverides!.ToArray());
}
public long TitleEncryptionKey { get; internal set; }
public long DescriptionEncryptionKey { get; internal set; }
public EncoderType TitleEncoderType { get; internal set; }
public EncoderType DescriptionEncoderType { get; internal set; }
}