/**
 * `@platform-modules/billing` — thin money-seam (provider axis + webhook ingest + settle/refund funnels).
 */

type ChargeRequest = {
    chargeKey: string;
    amount: number;
    currency: string;
    metadata?: Record<string, string>;
};
type ChargeResult = {
    kind: 'requires_client_action';
    chargeKey: string;
    providerRef: string;
    clientSecret: string;
} | {
    kind: 'settled';
    chargeKey: string;
    providerRef: string;
    amount: number;
    currency: string;
    documentUrls?: string[];
};
type RefundRequest = {
    refundKey: string;
    chargeKey: string;
    refundId: string;
    providerChargeId?: string;
    amount: number;
};
type RefundResult = {
    kind: 'refunded';
    refundKey: string;
    chargeKey: string;
    providerRef: string;
    amount: number;
    currency: string;
} | {
    kind: 'pending';
};
type RefundReconciliationRequest = {
    providerChargeId: string;
    amountMinor: bigint;
    currency: string;
    refundKey: string;
};
type RefundReconciliationResult = {
    kind: 'confirmed';
    providerRefundId: string;
    amountMinor: bigint;
    currency: string;
} | {
    kind: 'pending_or_unknown';
} | {
    kind: 'definite_failure';
    code: string;
};
type ProviderEvent = {
    eventId: string;
    kind: 'settlement';
    chargeKey: string;
    providerRef: string;
    amount: number;
    currency: string;
    documentUrls?: string[];
    subscriptionId?: string;
    period?: string;
    amountMinor?: bigint;
} | {
    eventId: string;
    kind: 'refund';
    refundKey: string;
    chargeKey: string;
    providerChargeId: string;
    providerRef: string;
    amount: number;
    currency: string;
} | {
    eventId: string;
    kind: 'other';
    raw: unknown;
};
interface PaymentProvider {
    readonly provider: string;
    readonly emitsInvoiceOnCharge: boolean;
    charge(req: ChargeRequest): Promise<ChargeResult>;
    refund(req: RefundRequest): Promise<RefundResult>;
    reconcileRefund(req: RefundReconciliationRequest): Promise<RefundReconciliationResult>;
    parseWebhook(raw: string, headers: Headers): Promise<ProviderEvent>;
}

type CreateSubscriptionInput = {
    idempotencyKey: string;
    planId: string;
    currentPeriod: string;
    status?: string;
};
type Subscription = {
    id: string;
    status: string;
    currentPeriod: string;
    planId: string;
};

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

type PaypalCreds = {
    clientId: string;
    clientSecret: string;
    webhookId: string;
    apiBaseUrl?: string;
    fetch?: typeof fetch;
};
type PaypalMoney = {
    currency_code?: string;
    currency?: string;
    value?: string;
    total?: string;
};
type PaypalLink = {
    href?: string;
    rel?: string;
    method?: string;
};
type PaypalOrder = {
    id?: string;
    status?: string;
    links?: PaypalLink[];
    purchase_units?: Array<{
        payments?: {
            captures?: Array<{
                id?: string;
                status?: string;
                amount?: PaypalMoney;
            }>;
        };
    }>;
};
type PaypalCapture = {
    id?: string;
    amount?: PaypalMoney;
};
type PaypalRefund = {
    id?: string;
    status?: string;
    amount?: PaypalMoney;
};
type PaypalSubscriptionRecord = {
    id?: string;
    status?: string;
    plan_id?: string;
    custom_id?: string;
    start_time?: string;
};
type PaypalWebhookHeaders = {
    authAlgo: string;
    certUrl: string;
    signature: string;
    transmissionId: string;
    transmissionTime: string;
};
type PaypalWebhookEvent = {
    id?: string;
    event_type?: string;
    resource?: Record<string, unknown>;
};
declare class PaypalApiError extends Error {
    readonly path: string;
    readonly status: number;
    readonly body: unknown;
    readonly name = "PaypalApiError";
    constructor(path: string, status: number, body: unknown);
}
declare class PaypalPayloadError extends Error {
    readonly name = "PaypalPayloadError";
    constructor(message: string);
}

declare class PaypalProvider implements PaymentProvider, SubscriptionProvider {
    private readonly creds;
    readonly provider = "paypal";
    readonly emitsInvoiceOnCharge = false;
    private readonly client;
    constructor(creds: PaypalCreds);
    charge(req: ChargeRequest): Promise<ChargeResult>;
    refund(req: RefundRequest): Promise<RefundResult>;
    reconcileRefund(req: RefundReconciliationRequest): Promise<RefundReconciliationResult>;
    parseWebhook(raw: string, headers: Headers): Promise<ProviderEvent>;
    parseWebhook(headers: Headers, raw: string): Promise<ProviderEvent>;
    createSubscription(input: CreateSubscriptionInput): Promise<Subscription>;
    cancelSubscription(id: string): Promise<void>;
    getSubscription(id: string): Promise<Subscription>;
}

export { PaypalApiError, type PaypalCapture, type PaypalCreds, type PaypalLink, type PaypalMoney, type PaypalOrder, PaypalPayloadError, PaypalProvider, type PaypalRefund, type PaypalSubscriptionRecord, type PaypalWebhookEvent, type PaypalWebhookHeaders };
