import { Schema } from '@platform-modules/db';
import { LedgerDbBag, ProviderEvent } from '../index.js';
import '@platform-modules/ledger';

type CreateSubscriptionInput = {
    idempotencyKey: string;
    planId: string;
    currentPeriod: string;
    status?: string;
};
type Subscription = {
    id: string;
    status: string;
    currentPeriod: string;
    planId: string;
};
type ParsedSubscriptionWebhook = {
    kind: 'settlement';
    subscriptionId: string;
    period: string;
    amountMinor: bigint;
    currency: string;
    eventId?: string;
} | {
    kind: 'other';
    raw: unknown;
    eventId?: string;
};

interface SubscriptionProvider {
    createSubscription(input: CreateSubscriptionInput): Promise<Subscription>;
    cancelSubscription(id: string): Promise<void>;
    getSubscription(id: string): Promise<Subscription>;
}

interface SubscriptionWebhookProvider extends SubscriptionProvider {
    parseWebhook(rawEvent: unknown): Promise<ParsedSubscriptionWebhook>;
}
type IngestWebhookDeps<S extends Schema = Schema> = LedgerDbBag<S> & {
    provider: SubscriptionWebhookProvider;
};
declare function buildChargeKey(subscriptionId: string, period: string): string;
declare function ingestWebhook<S extends Schema = Schema>(deps: IngestWebhookDeps<S>, rawEvent: unknown): Promise<ProviderEvent>;

export { type CreateSubscriptionInput, type IngestWebhookDeps, type ParsedSubscriptionWebhook, type Subscription, type SubscriptionProvider, type SubscriptionWebhookProvider, buildChargeKey, ingestWebhook };
