using CryptoExchange.Net.Converters;
using CryptoExchange.Net.Interfaces;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.Objects.Sockets;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace CryptoExchange.Net.Sockets
{
///
/// Subscription base
///
public abstract class Subscription
{
private bool _outputOriginalData;
///
/// Logger
///
protected readonly ILogger _logger;
///
/// If the subscription is a private subscription and needs authentication
///
public bool Authenticated { get; }
public abstract List Identifiers { get; }
///
/// ctor
///
///
///
///
public Subscription(ILogger logger, ISocketApiClient apiClient, bool authenticated)
{
_logger = logger;
_outputOriginalData = apiClient.ApiOptions.OutputOriginalData ?? apiClient.ClientOptions.OutputOriginalData;
Authenticated = authenticated;
}
///
/// Get the subscribe object to send when subscribing
///
///
public abstract object? GetSubRequest();
///
/// Check if the message is the response to the subscribe request
///
///
///
public abstract (bool, CallResult?) MessageMatchesSubRequest(ParsedMessage message);
///
/// Get the unsubscribe object to send when unsubscribing
///
///
public abstract object? GetUnsubRequest();
///
/// Check if the message is the response to the unsubscribe request
///
///
///
public abstract (bool, CallResult?) MessageMatchesUnsubRequest(ParsedMessage message);
///
/// Check if the message is an update for this subscription
///
///
///
public abstract bool MessageMatchesEvent(ParsedMessage message);
///
/// Handle the update message
///
///
///
public abstract Task HandleEventAsync(DataEvent message);
/////
///// Create a data event
/////
/////
/////
/////
/////
/////
/////
//protected virtual DataEvent CreateDataEvent(T obj, ParsedMessage message, string? topic = null, SocketUpdateType? type = null)
//{
// string? originalData = null;
// if (_outputOriginalData)
// originalData = message.Get(ParsingUtils.GetString);
// return new DataEvent(obj, topic, originalData, message.Timestamp, type);
//}
/////
///// Deserialize the message to an object using Json.Net
/////
/////
/////
/////
/////
//protected virtual Task> DeserializeAsync(StreamMessage message, JsonSerializerSettings settings)
//{
// var serializer = JsonSerializer.Create(settings);
// using var sr = new StreamReader(message.Stream, Encoding.UTF8, false, (int)message.Stream.Length, true);
// using var jsonTextReader = new JsonTextReader(sr);
// var result = serializer.Deserialize(jsonTextReader);
// message.Stream.Position = 0;
// return Task.FromResult(new CallResult(result!));
//}
}
}