using System.Net.Http.Json;
using System.Text.Json;
using System.Web;
namespace Synor.Sdk.Database;
///
/// Synor Database SDK client for C#.
///
/// Provides multi-model database with Key-Value, Document, Vector, and Time Series stores.
///
///
///
/// var db = new SynorDatabase(new DatabaseConfig { ApiKey = "your-api-key" });
///
/// // Key-Value operations
/// await db.Kv.SetAsync("mykey", "myvalue");
/// var value = await db.Kv.GetAsync("mykey");
///
/// // Document operations
/// var id = await db.Documents.CreateAsync("users", new { name = "Alice", age = 30 });
/// var doc = await db.Documents.GetAsync("users", id);
///
/// db.Dispose();
///
///
public class SynorDatabase : IDisposable
{
private readonly DatabaseConfig _config;
private readonly HttpClient _httpClient;
private readonly JsonSerializerOptions _jsonOptions;
private bool _disposed;
public KeyValueStore Kv { get; }
public DocumentStore Documents { get; }
public VectorStore Vectors { get; }
public TimeSeriesStore TimeSeries { get; }
public SynorDatabase(DatabaseConfig config)
{
_config = config;
_httpClient = new HttpClient
{
BaseAddress = new Uri(config.Endpoint),
Timeout = config.Timeout
};
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {config.ApiKey}");
_httpClient.DefaultRequestHeaders.Add("X-SDK-Version", "csharp/0.1.0");
_jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
PropertyNameCaseInsensitive = true
};
Kv = new KeyValueStore(this);
Documents = new DocumentStore(this);
Vectors = new VectorStore(this);
TimeSeries = new TimeSeriesStore(this);
}
///
/// Key-Value store operations.
///
public class KeyValueStore
{
private readonly SynorDatabase _db;
internal KeyValueStore(SynorDatabase db) => _db = db;
public async Task