Files
BotPages/BotPages.Core/Context/PageContext.cs

66 lines
2.4 KiB
C#

using BotPages.Core.Abstractions;
using BotPages.Core.Context;
namespace BotPages.Core;
/// <summary>
/// Контекст страницы, объединяющий пользователя, чат, состояние и адаптер.
/// </summary>
public sealed class PageContext
{
/// <summary>Ключ сессии.</summary>
public required CompositeSessionKey SessionKey { get; init; }
/// <summary>Данные обновления.</summary>
public required UpdateContext Update { get; init; }
/// <summary>Хранилище состояния.</summary>
public required IStateStorage StateStorage { get; init; }
/// <summary>Сервис навигации.</summary>
public required NavigationService Navigation { get; init; }
/// <summary>Фабрика адаптеров (для получения других адаптеров).</summary>
public required IMessengerAdapterFactory AdapterFactory { get; init; }
/// <summary>Текущий адаптер мессенджера.</summary>
public required IMessengerAdapter Adapter { get; init; }
/// <summary>
/// Получить билдер альбомов.
/// </summary>
public IAlbumBuilder Albums => Adapter.CreateAlbumBuilder(this);
/// <summary>
/// Получить адаптер по ID.
/// </summary>
public IMessengerAdapter GetAdapter(string adapterId)
=> AdapterFactory.Resolve(adapterId);
/// <summary>
/// Попытаться получить адаптер по ID.
/// </summary>
public bool TryGetAdapter(string adapterId, out IMessengerAdapter? adapter)
=> AdapterFactory.TryResolve(adapterId, out adapter);
/// <summary>
/// Получить все адаптеры определенного типа.
/// </summary>
public IReadOnlyList<IMessengerAdapter> GetAdaptersByType(string adapterType)
=> AdapterFactory.GetAdaptersByType(adapterType);
/// <summary>
/// Получить текущий тип адаптера.
/// </summary>
public string CurrentAdapterType => Update.Adapter.Type;
/// <summary>
/// Получить текущий ID адаптера.
/// </summary>
public string CurrentAdapterId => Update.Adapter.Id;
/// <summary>
/// Получить все адаптеры.
/// </summary>
public IReadOnlyList<IMessengerAdapter> AllAdapters => AdapterFactory.AllAdapters;
}