#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <mw/error.hpp>
namespace telegrammer
{
/// Durable callback registration owned by one API key.
struct Subscription
{
/// Stable subscription identifier.
int64_t id;
/// API-key identity that owns the registration.
int64_t owner_id;
/// Telegram chat receiving the subscription.
int64_t chat_id;
/// Canonical HTTP or HTTPS callback URL.
std::string callback_url;
/// Creation time as Unix seconds.
int64_t created_at;
};
/// Persists callback subscriptions and enforces their ownership limits.
class SubscriptionStore
{
public:
/// Construct a store backed by the supplied SQLite database.
explicit SubscriptionStore(std::string db_path);
/// Insert an owned subscription, or return the existing identical row.
mw::E<Subscription> add(int64_t owner_id, int64_t chat_id,
const std::string& callback_url) const;
/// List subscriptions owned by one API key.
mw::E<std::vector<Subscription>> list(int64_t owner_id) const;
/// Delete an owned subscription and its queued deliveries.
mw::E<bool> remove(int64_t owner_id, int64_t subscription_id) const;
private:
std::string db_path_;
};
} // namespace telegrammer