import { Alepha, Middleware, Static, TNull, TObject, TOptional, TSchema, TUnion } from "alepha";
import { Page } from "alepha/orm";
import { DateTimeProvider } from "alepha/datetime";
import { PaymentService } from "alepha/api/payments";
import { CacheProvider } from "alepha/cache";
import { BuildExtraConfigColumns, SQL } from "drizzle-orm";
import { PgColumnBuilderBase, PgSequenceOptions, PgTableExtraConfigValue, UpdateDeleteAction } from "drizzle-orm/pg-core";
import "drizzle-orm/pg-core/foreign-keys";
import "drizzle-orm/pg-core/session";
import "alepha/crypto";
import "drizzle-kit/api";
import "drizzle-orm/d1";
import "drizzle-orm/sqlite-core";
//#region ../../src/orm/core/schemas/insertSchema.d.ts
/**
 * Transforms a TObject schema for insert operations.
 * All default properties at the root level are made optional.
 * Generated columns are excluded entirely.
 *
 * @example
 * Before: { name: string; age: number(default=0); fullName: generated }
 * After:  { name: string; age?: number; }
 */
type TObjectInsert<T extends TObject> = TObject<{ [K in keyof T["shape"] as T["shape"][K] extends {
  [PG_GENERATED]: any;
} ? never : K]: T["shape"][K] extends {
  [PG_DEFAULT]: any;
} | {
  [PG_ORGANIZATION]: any;
} ? TOptional<Extract<T["shape"][K], TSchema>> : T["shape"][K]; }>;
//#endregion
//#region ../../src/orm/core/schemas/updateSchema.d.ts
/**
 * Transforms a TObject schema for update operations.
 * All optional properties at the root level are made nullable (i.e., `T | null`).
 * Generated columns are excluded entirely.
 *
 * @example
 * Before: { name?: string; age: number; fullName: generated }
 * After:  { name?: string | null; age: number; }
 */
type TObjectUpdate<T extends TObject> = TObject<{ [K in keyof T["shape"] as T["shape"][K] extends {
  [PG_GENERATED]: any;
} ? never : K]: T["shape"][K] extends TOptional<infer U extends TSchema> ? TOptional<TUnion<[U, TNull]>> : T["shape"][K]; }>;
//#endregion
//#region ../../src/orm/core/primitives/$entity.d.ts
interface EntityPrimitiveOptions<T extends TObject, Keys = keyof Static<T>> {
  /**
   * The database table name that will be created for this entity.
   * If not provided, name will be inferred from the $repository variable name.
   */
  name: string;
  /**
   * TypeBox schema defining the table structure and column types.
   */
  schema: T;
  /**
   * Database indexes to create for query optimization.
   */
  indexes?: (Keys | {
    /**
     * Single column to index.
     */
    column: Keys;
    /**
     * Whether this should be a unique index (enforces uniqueness constraint).
     */
    unique?: boolean;
    /**
     * Custom name for the index. If not provided, generates name automatically.
     */
    name?: string;
    /**
     * Partial index condition. Only rows matching this SQL expression are indexed.
     */
    where?: SQL;
  } | {
    /**
     * Multiple columns for composite index (order matters for query optimization).
     */
    columns: Keys[];
    /**
     * Whether this should be a unique index (enforces uniqueness constraint).
     */
    unique?: boolean;
    /**
     * Custom name for the index. If not provided, generates name automatically.
     */
    name?: string;
    /**
     * Partial index condition. Only rows matching this SQL expression are indexed.
     */
    where?: SQL;
  } | {
    /**
     * SQL expressions for expression-based indexes.
     *
     * Can include column references and SQL functions like `LOWER()`, `UPPER()`, etc.
     * Columns and expressions can be mixed together.
     *
     * @example
     * ```ts
     * // Case-insensitive unique username per realm
     * indexes: [{
     *   expressions: (self) => [self.realm, sql`LOWER(${self.username})`],
     *   unique: true,
     *   name: "users_realm_username_lower_idx",
     * }]
     * ```
     */
    expressions: (self: Record<Keys & string, any>) => (SQL | any)[];
    /**
     * Whether this should be a unique index (enforces uniqueness constraint).
     */
    unique?: boolean;
    /**
     * Custom name for the index. If not provided, generates name automatically.
     */
    name: string;
    /**
     * Partial index condition. Only rows matching this SQL expression are indexed.
     */
    where?: SQL;
  })[];
  /**
   * Foreign key constraints to maintain referential integrity.
   */
  foreignKeys?: Array<{
    /**
     * Optional name for the foreign key constraint.
     */
    name?: string;
    /**
     * Local columns that reference the foreign table.
     */
    columns: Array<keyof Static<T>>;
    /**
     * Referenced columns in the foreign table.
     * Must be EntityColumn references from other entities.
     */
    foreignColumns: Array<() => EntityColumn<any>>;
  }>;
  /**
   * Additional table constraints for data validation.
   *
   * Constraints enforce business rules at the database level, providing
   * an additional layer of data integrity beyond application validation.
   *
   * **Constraint Types**:
   * - **Unique constraints**: Prevent duplicate values across columns
   * - **Check constraints**: Enforce custom validation rules with SQL expressions
   *
   * @example
   * ```ts
   * constraints: [
   *   {
   *     name: "unique_user_email",
   *     columns: ["email"],
   *     unique: true
   *   },
   *   {
   *     name: "valid_age_range",
   *     columns: ["age"],
   *     check: sql`age >= 0 AND age <= 150`
   *   },
   *   {
   *     name: "unique_user_username_per_tenant",
   *     columns: ["tenantId", "username"],
   *     unique: true
   *   }
   * ]
   * ```
   */
  constraints?: Array<{
    /**
     * Columns involved in this constraint.
     */
    columns: Array<keyof Static<T>>;
    /**
     * Optional name for the constraint.
     */
    name?: string;
    /**
     * Whether this is a unique constraint.
     */
    unique?: boolean | {};
    /**
     * SQL expression for check constraint validation.
     */
    check?: SQL;
  }>;
  /**
   * Advanced Drizzle ORM configuration for complex table setups.
   */
  config?: (self: BuildExtraConfigColumns<string, FromSchema<T>, "pg">) => PgTableExtraConfigValue[];
}
declare class EntityPrimitive<T extends TObject = TObject> {
  readonly options: EntityPrimitiveOptions<T>;
  constructor(options: EntityPrimitiveOptions<T>);
  alias(alias: string): this;
  get cols(): EntityColumns<T>;
  get name(): string;
  get schema(): T;
  protected _insertSchema?: TObjectInsert<T>;
  get insertSchema(): TObjectInsert<T>;
  protected _updateSchema?: TObjectUpdate<T>;
  get updateSchema(): TObjectUpdate<T>;
}
/**
 * Convert a schema to columns.
 */
type FromSchema<T extends TObject> = { [key in keyof T["properties"]]: PgColumnBuilderBase; };
type EntityColumn<T extends TObject> = {
  name: string;
  entity: EntityPrimitive<T>;
};
type EntityColumns<T extends TObject> = { [key in keyof T["properties"]]: EntityColumn<T>; };
//#endregion
//#region ../../src/orm/core/constants/PG_SYMBOLS.d.ts
declare const PG_DEFAULT: unique symbol;
declare const PG_PRIMARY_KEY: unique symbol;
declare const PG_CREATED_AT: unique symbol;
declare const PG_UPDATED_AT: unique symbol;
declare const PG_DELETED_AT: unique symbol;
declare const PG_VERSION: unique symbol;
declare const PG_IDENTITY: unique symbol;
declare const PG_ENUM: unique symbol;
declare const PG_REF: unique symbol;
declare const PG_GENERATED: unique symbol;
declare const PG_ORGANIZATION: unique symbol;
/**
 * @deprecated Use `PG_IDENTITY` instead.
 */
declare const PG_SERIAL: unique symbol;
type PgSymbols = {
  [PG_DEFAULT]: {};
  [PG_PRIMARY_KEY]: {};
  [PG_CREATED_AT]: {};
  [PG_UPDATED_AT]: {};
  [PG_DELETED_AT]: {};
  [PG_VERSION]: {};
  [PG_IDENTITY]: PgIdentityOptions;
  [PG_REF]: PgRefOptions;
  [PG_ENUM]: PgEnumOptions;
  [PG_GENERATED]: PgGeneratedOptions;
  [PG_ORGANIZATION]: PgOrganizationOptions;
  /**
   * @deprecated Use `PG_IDENTITY` instead.
   */
  [PG_SERIAL]: {};
};
type PgSymbolKeys = keyof PgSymbols;
interface PgOrganizationOptions {
  /**
   * Fail-closed tenant scoping. When `true`, the repository (a) refuses any
   * read/write with no resolved tenant instead of falling through to an
   * unfiltered "see/write everything" query, and (b) drops the
   * `OR organizationId IS NULL` "global row" escape — a scoped tenant never
   * sees NULL/global rows. Use for security-sensitive tables. Defaults to
   * `false` (the historic fail-open semantics).
   */
  strict?: boolean;
}
type PgIdentityOptions = {
  mode: "always" | "byDefault";
} & PgSequenceOptions & {
  name?: string;
};
interface PgEnumOptions {
  name?: string;
  description?: string;
}
interface PgGeneratedOptions {
  /**
   * SQL expression for the generated column.
   */
  expression: SQL;
  /**
   * Storage mode for the generated column.
   * - `"stored"` — value is computed on write and stored on disk (default for PostgreSQL).
   * - `"virtual"` — value is computed on read (default for SQLite).
   */
  mode?: "stored" | "virtual";
}
interface PgRefOptions {
  ref: () => {
    name: string;
    entity: EntityPrimitive;
  };
  actions?: {
    onUpdate?: UpdateDeleteAction;
    onDelete?: UpdateDeleteAction;
  };
}
//#endregion
//#region ../../src/orm/core/helpers/pgAttr.d.ts
/**
 * Type representation.
 */
type PgAttr<T extends TSchema, TAttr extends PgSymbolKeys> = T & { [K in TAttr]: PgSymbols[K]; };
//#endregion
//#region ../../src/orm/core/schemas/databaseEnvSchema.d.ts
/**
 * Base database environment schema.
 *
 * Defines the `DATABASE_URL` connection string used by all ORM providers
 * to determine the database driver and connection target.
 *
 * Supported URL formats:
 * - `sqlite://:memory:` or `sqlite://./path/to/db` — SQLite (Node.js or Bun)
 * - `postgres://user:password@host:port/database` — PostgreSQL (Node.js or Bun)
 * - `pglite://:memory:` or `pglite://./path` — PGlite (embedded Postgres)
 * - `d1://BINDING_NAME` — Cloudflare D1
 * - `hyperdrive://BINDING_NAME` — Cloudflare Hyperdrive
 */
declare const databaseEnvSchema: import("zod").ZodObject<{
  DATABASE_URL: import("zod").ZodOptional<import("zod").ZodString>;
  DATABASE_SYNC: import("zod").ZodOptional<import("zod").ZodBoolean>;
}, import("zod/v4/core").$strip>;
declare module "alepha" {
  interface Env extends Partial<Static<typeof databaseEnvSchema>> {}
}
//#endregion
//#region ../../src/api/subscriptions/schemas/planDefinitionSchema.d.ts
declare const planDefinitionSchema: import("zod").ZodObject<{
  id: import("zod").ZodString;
  name: import("zod").ZodString;
  description: import("zod").ZodOptional<import("zod").ZodString>;
  available: import("zod").ZodDefault<import("zod").ZodBoolean>;
  pricing: import("zod").ZodArray<import("zod").ZodObject<{
    interval: import("zod").ZodEnum<{
      monthly: "monthly";
      yearly: "yearly";
    }>;
    amount: import("zod").ZodInt;
    currency: import("zod").ZodString;
  }, import("zod/v4/core").$strip>>;
  trial: import("zod").ZodOptional<import("zod").ZodObject<{
    days: import("zod").ZodInt;
    requirePaymentMethod: import("zod").ZodDefault<import("zod").ZodBoolean>;
  }, import("zod/v4/core").$strip>>;
  features: import("zod").ZodArray<import("zod").ZodString>;
  limits: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodInt>;
  order: import("zod").ZodDefault<import("zod").ZodInt>;
  metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
}, import("zod/v4/core").$strip>;
type PlanDefinition = Static<typeof planDefinitionSchema>;
//#endregion
//#region ../../src/api/subscriptions/schemas/subscriptionSettingsSchema.d.ts
declare const subscriptionSettingsSchema: import("zod").ZodObject<{
  trialDays: import("zod").ZodDefault<import("zod").ZodInt>;
  gracePeriodDays: import("zod").ZodDefault<import("zod").ZodInt>;
  dunningSchedule: import("zod").ZodArray<import("zod").ZodInt>;
  cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
  prorateOnChange: import("zod").ZodDefault<import("zod").ZodBoolean>;
}, import("zod/v4/core").$strip>;
type SubscriptionSettings = Static<typeof subscriptionSettingsSchema>;
//#endregion
//#region ../../src/api/subscriptions/services/SubscriptionConfig.d.ts
declare class SubscriptionConfig {
  protected readonly plans: import("alepha/api/parameters").ParameterPrimitive<import("zod").ZodObject<{
    plans: import("zod").ZodArray<import("zod").ZodObject<{
      id: import("zod").ZodString;
      name: import("zod").ZodString;
      description: import("zod").ZodOptional<import("zod").ZodString>;
      available: import("zod").ZodDefault<import("zod").ZodBoolean>;
      pricing: import("zod").ZodArray<import("zod").ZodObject<{
        interval: import("zod").ZodEnum<{
          monthly: "monthly";
          yearly: "yearly";
        }>;
        amount: import("zod").ZodInt;
        currency: import("zod").ZodString;
      }, import("zod/v4/core").$strip>>;
      trial: import("zod").ZodOptional<import("zod").ZodObject<{
        days: import("zod").ZodInt;
        requirePaymentMethod: import("zod").ZodDefault<import("zod").ZodBoolean>;
      }, import("zod/v4/core").$strip>>;
      features: import("zod").ZodArray<import("zod").ZodString>;
      limits: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodInt>;
      order: import("zod").ZodDefault<import("zod").ZodInt>;
      metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
    }, import("zod/v4/core").$strip>>;
  }, import("zod/v4/core").$strip>>;
  protected readonly settings: import("alepha/api/parameters").ParameterPrimitive<import("zod").ZodObject<{
    trialDays: import("zod").ZodDefault<import("zod").ZodInt>;
    gracePeriodDays: import("zod").ZodDefault<import("zod").ZodInt>;
    dunningSchedule: import("zod").ZodArray<import("zod").ZodInt>;
    cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
    prorateOnChange: import("zod").ZodDefault<import("zod").ZodBoolean>;
  }, import("zod/v4/core").$strip>>;
  getPlans(): Promise<PlanDefinition[]>;
  getSettings(): Promise<SubscriptionSettings>;
  getPlan(planId: string): Promise<PlanDefinition>;
  getPlanPricing(planId: string, interval: "monthly" | "yearly"): Promise<{
    interval: "monthly" | "yearly";
    amount: number;
    currency: string;
  }>;
}
//#endregion
//#region ../../src/api/subscriptions/entities/subscriptionEvents.d.ts
declare const subscriptionEvents: import("alepha/orm").EntityPrimitive<import("zod").ZodObject<{
  id: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_PRIMARY_KEY>, typeof import("alepha/orm").PG_DEFAULT>;
  createdAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_CREATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
  subscriptionId: import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_REF>;
  organizationId: import("alepha/orm").PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof import("alepha/orm").PG_ORGANIZATION>;
  type: import("zod").ZodEnum<{
    activated: "activated";
    cancelled: "cancelled";
    created: "created";
    expired: "expired";
    past_due: "past_due";
    payment_failed: "payment_failed";
    payment_retried: "payment_retried";
    plan_change_scheduled: "plan_change_scheduled";
    plan_changed: "plan_changed";
    reactivated: "reactivated";
    renewed: "renewed";
    resumed: "resumed";
    suspended: "suspended";
    trial_ended: "trial_ended";
    trial_started: "trial_started";
  }>;
  previousStatus: import("zod").ZodOptional<import("zod").ZodString>;
  newStatus: import("zod").ZodOptional<import("zod").ZodString>;
  previousPlanId: import("zod").ZodOptional<import("zod").ZodString>;
  newPlanId: import("zod").ZodOptional<import("zod").ZodString>;
  paymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
  amount: import("zod").ZodOptional<import("zod").ZodInt>;
  currency: import("zod").ZodOptional<import("zod").ZodString>;
  triggeredBy: import("zod").ZodOptional<import("zod").ZodString>;
  userId: import("zod").ZodOptional<import("zod").ZodString>;
  note: import("zod").ZodOptional<import("zod").ZodString>;
}, import("zod/v4/core").$strip>>;
type SubscriptionEventEntity = Static<typeof subscriptionEvents.schema>;
//#endregion
//#region ../../src/api/subscriptions/entities/subscriptions.d.ts
declare const subscriptions: import("alepha/orm").EntityPrimitive<import("zod").ZodObject<{
  id: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_PRIMARY_KEY>, typeof import("alepha/orm").PG_DEFAULT>;
  version: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodInt, typeof import("alepha/orm").PG_VERSION>, typeof import("alepha/orm").PG_DEFAULT>;
  createdAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_CREATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
  updatedAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_UPDATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
  organizationId: import("alepha/orm").PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof import("alepha/orm").PG_ORGANIZATION>;
  planId: import("zod").ZodString;
  interval: import("zod").ZodEnum<{
    monthly: "monthly";
    yearly: "yearly";
  }>;
  status: import("zod").ZodEnum<{
    active: "active";
    cancelled: "cancelled";
    expired: "expired";
    past_due: "past_due";
    suspended: "suspended";
    trialing: "trialing";
  }>;
  currentPeriodStart: import("zod").ZodString;
  currentPeriodEnd: import("zod").ZodString;
  trialStart: import("zod").ZodOptional<import("zod").ZodString>;
  trialEnd: import("zod").ZodOptional<import("zod").ZodString>;
  cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
  cancelReason: import("zod").ZodOptional<import("zod").ZodString>;
  cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
  lastPaymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
  lastPaymentAt: import("zod").ZodOptional<import("zod").ZodString>;
  nextBillingAt: import("zod").ZodOptional<import("zod").ZodString>;
  dunningStartedAt: import("zod").ZodOptional<import("zod").ZodString>;
  dunningAttempt: import("zod").ZodDefault<import("zod").ZodInt>;
  dunningNextRetryAt: import("zod").ZodOptional<import("zod").ZodString>;
  pendingPlanId: import("zod").ZodOptional<import("zod").ZodString>;
  pendingInterval: import("zod").ZodOptional<import("zod").ZodEnum<{
    monthly: "monthly";
    yearly: "yearly";
  }>>;
  metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
}, import("zod/v4/core").$strip>>;
type SubscriptionEntity = Static<typeof subscriptions.schema>;
//#endregion
//#region ../../src/api/subscriptions/schemas/entitlementsSchema.d.ts
declare const entitlementsSchema: import("zod").ZodObject<{
  planId: import("zod").ZodString;
  planName: import("zod").ZodString;
  status: import("zod").ZodEnum<{
    active: "active";
    cancelled: "cancelled";
    expired: "expired";
    past_due: "past_due";
    suspended: "suspended";
    trialing: "trialing";
  }>;
  features: import("zod").ZodArray<import("zod").ZodString>;
  limits: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodInt>;
  trialEndsAt: import("zod").ZodOptional<import("zod").ZodString>;
  periodEndsAt: import("zod").ZodString;
  cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
}, import("zod/v4/core").$strip>;
type Entitlements = Static<typeof entitlementsSchema>;
//#endregion
//#region ../../src/api/subscriptions/schemas/subscriptionQuerySchema.d.ts
declare const subscriptionQuerySchema: import("zod").ZodObject<{
  page: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodInt>>;
  size: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodInt>>;
  sort: import("zod").ZodOptional<import("zod").ZodString>;
  status: import("zod").ZodOptional<import("zod").ZodEnum<{
    active: "active";
    cancelled: "cancelled";
    expired: "expired";
    past_due: "past_due";
    suspended: "suspended";
    trialing: "trialing";
  }>>;
  planId: import("zod").ZodOptional<import("zod").ZodString>;
  organizationId: import("zod").ZodOptional<import("zod").ZodString>;
}, import("zod/v4/core").$strip>;
type SubscriptionQuery = Static<typeof subscriptionQuerySchema>;
//#endregion
//#region ../../src/api/subscriptions/schemas/subscriptionStatsSchema.d.ts
declare const subscriptionStatsSchema: import("zod").ZodObject<{
  total: import("zod").ZodInt;
  trialing: import("zod").ZodInt;
  active: import("zod").ZodInt;
  pastDue: import("zod").ZodInt;
  suspended: import("zod").ZodInt;
  cancelled: import("zod").ZodInt;
  expired: import("zod").ZodInt;
  trialConversionRate: import("zod").ZodNumber;
  churnRate: import("zod").ZodNumber;
  byPlan: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
    active: import("zod").ZodInt;
    trialing: import("zod").ZodInt;
    total: import("zod").ZodInt;
  }, import("zod/v4/core").$strip>>;
}, import("zod/v4/core").$strip>;
type SubscriptionStats = Static<typeof subscriptionStatsSchema>;
//#endregion
//#region ../../src/api/subscriptions/services/SubscriptionService.d.ts
interface SubscribeOptions {
  /**
   * Override plan/global trial days.
   */
  trialDays?: number;
  /**
   * Go straight to active (requires payment).
   */
  skipTrial?: boolean;
  /**
   * Metadata to attach to the subscription.
   */
  metadata?: Record<string, unknown>;
}
interface CancelOptions {
  /**
   * Cancellation reason.
   */
  reason?: string;
  /**
   * Cancel immediately instead of at period end.
   */
  immediate?: boolean;
  /**
   * User who initiated the cancellation.
   */
  cancelledBy?: string;
}
interface ChangePlanOptions {
  /**
   * Apply now (with proration) or at period end.
   */
  immediate?: boolean;
  /**
   * Override settings.prorateOnChange.
   */
  prorate?: boolean;
}
interface EventContext$2 {
  previousStatus?: string;
  newStatus?: string;
  previousPlanId?: string;
  newPlanId?: string;
  paymentIntentId?: string;
  amount?: number;
  currency?: string;
  triggeredBy?: string;
  userId?: string;
  note?: string;
}
declare class SubscriptionService {
  protected readonly alepha: Alepha;
  protected readonly log: import("alepha/logger").Logger;
  protected readonly dateTime: DateTimeProvider;
  protected readonly subscriptionRepo: import("alepha/orm").Repository<import("zod").ZodObject<{
    id: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_PRIMARY_KEY>, typeof import("alepha/orm").PG_DEFAULT>;
    version: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodInt, typeof import("alepha/orm").PG_VERSION>, typeof import("alepha/orm").PG_DEFAULT>;
    createdAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_CREATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
    updatedAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_UPDATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
    organizationId: import("alepha/orm").PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof import("alepha/orm").PG_ORGANIZATION>;
    planId: import("zod").ZodString;
    interval: import("zod").ZodEnum<{
      monthly: "monthly";
      yearly: "yearly";
    }>;
    status: import("zod").ZodEnum<{
      active: "active";
      cancelled: "cancelled";
      expired: "expired";
      past_due: "past_due";
      suspended: "suspended";
      trialing: "trialing";
    }>;
    currentPeriodStart: import("zod").ZodString;
    currentPeriodEnd: import("zod").ZodString;
    trialStart: import("zod").ZodOptional<import("zod").ZodString>;
    trialEnd: import("zod").ZodOptional<import("zod").ZodString>;
    cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
    cancelReason: import("zod").ZodOptional<import("zod").ZodString>;
    cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
    lastPaymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
    lastPaymentAt: import("zod").ZodOptional<import("zod").ZodString>;
    nextBillingAt: import("zod").ZodOptional<import("zod").ZodString>;
    dunningStartedAt: import("zod").ZodOptional<import("zod").ZodString>;
    dunningAttempt: import("zod").ZodDefault<import("zod").ZodInt>;
    dunningNextRetryAt: import("zod").ZodOptional<import("zod").ZodString>;
    pendingPlanId: import("zod").ZodOptional<import("zod").ZodString>;
    pendingInterval: import("zod").ZodOptional<import("zod").ZodEnum<{
      monthly: "monthly";
      yearly: "yearly";
    }>>;
    metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
  }, import("zod/v4/core").$strip>>;
  protected readonly eventRepo: import("alepha/orm").Repository<import("zod").ZodObject<{
    id: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_PRIMARY_KEY>, typeof import("alepha/orm").PG_DEFAULT>;
    createdAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_CREATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
    subscriptionId: import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_REF>;
    organizationId: import("alepha/orm").PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof import("alepha/orm").PG_ORGANIZATION>;
    type: import("zod").ZodEnum<{
      activated: "activated";
      cancelled: "cancelled";
      created: "created";
      expired: "expired";
      past_due: "past_due";
      payment_failed: "payment_failed";
      payment_retried: "payment_retried";
      plan_change_scheduled: "plan_change_scheduled";
      plan_changed: "plan_changed";
      reactivated: "reactivated";
      renewed: "renewed";
      resumed: "resumed";
      suspended: "suspended";
      trial_ended: "trial_ended";
      trial_started: "trial_started";
    }>;
    previousStatus: import("zod").ZodOptional<import("zod").ZodString>;
    newStatus: import("zod").ZodOptional<import("zod").ZodString>;
    previousPlanId: import("zod").ZodOptional<import("zod").ZodString>;
    newPlanId: import("zod").ZodOptional<import("zod").ZodString>;
    paymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
    amount: import("zod").ZodOptional<import("zod").ZodInt>;
    currency: import("zod").ZodOptional<import("zod").ZodString>;
    triggeredBy: import("zod").ZodOptional<import("zod").ZodString>;
    userId: import("zod").ZodOptional<import("zod").ZodString>;
    note: import("zod").ZodOptional<import("zod").ZodString>;
  }, import("zod/v4/core").$strip>>;
  protected readonly config: SubscriptionConfig;
  /**
   * Find a subscription by organization ID.
   * Returns null if no subscription exists.
   */
  getByOrganization(organizationId: string): Promise<SubscriptionEntity | null>;
  /**
   * Get a subscription by ID. Throws NotFoundError if not found.
   */
  getSubscription(id: string): Promise<SubscriptionEntity>;
  /**
   * Returns true if the subscription currently grants access.
   * Accessible statuses: trialing, active, past_due (grace period),
   * or cancelled with cancelAtPeriodEnd before period end.
   */
  isAccessible(sub: SubscriptionEntity): boolean;
  /**
   * Record a subscription event in the event log.
   */
  recordEvent(subscriptionId: string, organizationId: string, type: SubscriptionEventEntity["type"], context?: EventContext$2): Promise<void>;
  /**
   * Compute the end of a billing interval from a start date.
   */
  computeIntervalEnd(start: string, interval: "monthly" | "yearly"): string;
  /**
   * Create a new subscription for an organization.
   */
  subscribe(organizationId: string, planId: string, interval: "monthly" | "yearly", options?: SubscribeOptions): Promise<SubscriptionEntity>;
  /**
   * Cancel a subscription.
   * If immediate, the subscription expires right away.
   * If at period end, the subscription remains accessible until the period ends.
   */
  cancel(subscriptionId: string, options?: CancelOptions): Promise<void>;
  /**
   * Resume a cancelled subscription before its period ends.
   * Only valid for subscriptions cancelled with cancelAtPeriodEnd.
   */
  resume(subscriptionId: string): Promise<void>;
  /**
   * Change the plan of a subscription.
   * If immediate, proration is calculated and the plan changes now.
   * If at period end, the change is scheduled for the next renewal.
   * Returns the net proration amount (positive = charge, negative = credit).
   */
  changePlan(subscriptionId: string, newPlanId: string, newInterval?: "monthly" | "yearly", options?: ChangePlanOptions): Promise<number>;
  /**
   * Reactivate a suspended subscription (admin action).
   * Resets dunning state and starts a new billing period.
   */
  reactivate(subscriptionId: string): Promise<void>;
  /**
   * Extend the trial period of a trialing subscription.
   */
  extendTrial(subscriptionId: string, days: number): Promise<void>;
  /**
   * Check if an organization has access to a specific feature.
   */
  can(organizationId: string, feature: string): Promise<boolean>;
  /**
   * Get the usage limit for a resource.
   * Returns -1 for unlimited, 0 for no access.
   */
  limit(organizationId: string, resource: string): Promise<number>;
  /**
   * Get the full entitlements snapshot for an organization.
   */
  getEntitlements(organizationId: string): Promise<Entitlements>;
  /**
   * Find subscriptions with pagination and filtering.
   */
  findSubscriptions(query?: SubscriptionQuery): Promise<Page<SubscriptionEntity>>;
  /**
   * Get the event history for a subscription, ordered by most recent first.
   */
  getHistory(subscriptionId: string): Promise<SubscriptionEventEntity[]>;
  /**
   * Get aggregated subscription statistics.
   */
  getStats(): Promise<SubscriptionStats>;
  /**
   * Get revenue data from recent subscription events.
   * Sums amounts from renewed and activated events within the specified window.
   */
  getRevenue(days?: number): Promise<{
    total: number;
    count: number;
  }>;
  /**
   * Calculate proration for a mid-cycle plan change.
   * Returns the net amount: positive = charge, negative = credit.
   */
  protected calculateProration(sub: SubscriptionEntity, newPlanId: string, newInterval: "monthly" | "yearly"): Promise<number>;
}
//#endregion
//#region ../../src/api/subscriptions/controllers/AdminSubscriptionController.d.ts
declare class AdminSubscriptionController {
  protected readonly url = "/subscriptions";
  protected readonly group = "admin:subscriptions";
  protected readonly service: SubscriptionService;
  protected readonly config: SubscriptionConfig;
  /**
   * Find subscriptions with pagination and filtering.
   */
  readonly findSubscriptions: import("alepha/server").ActionPrimitiveFn<{
    query: import("zod").ZodObject<{
      page: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodInt>>;
      size: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodInt>>;
      sort: import("zod").ZodOptional<import("zod").ZodString>;
      status: import("zod").ZodOptional<import("zod").ZodEnum<{
        active: "active";
        cancelled: "cancelled";
        expired: "expired";
        past_due: "past_due";
        suspended: "suspended";
        trialing: "trialing";
      }>>;
      planId: import("zod").ZodOptional<import("zod").ZodString>;
      organizationId: import("zod").ZodOptional<import("zod").ZodString>;
    }, import("zod/v4/core").$strip>;
    response: import("zod").ZodObject<{
      content: import("zod").ZodArray<import("zod").ZodObject<{
        id: PgAttr<PgAttr<import("zod").ZodString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
        version: PgAttr<PgAttr<import("zod").ZodInt, typeof PG_VERSION>, typeof PG_DEFAULT>;
        createdAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
        updatedAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
        organizationId: PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof PG_ORGANIZATION>;
        planId: import("zod").ZodString;
        interval: import("zod").ZodEnum<{
          monthly: "monthly";
          yearly: "yearly";
        }>;
        status: import("zod").ZodEnum<{
          active: "active";
          cancelled: "cancelled";
          expired: "expired";
          past_due: "past_due";
          suspended: "suspended";
          trialing: "trialing";
        }>;
        currentPeriodStart: import("zod").ZodString;
        currentPeriodEnd: import("zod").ZodString;
        trialStart: import("zod").ZodOptional<import("zod").ZodString>;
        trialEnd: import("zod").ZodOptional<import("zod").ZodString>;
        cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
        cancelReason: import("zod").ZodOptional<import("zod").ZodString>;
        cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
        lastPaymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
        lastPaymentAt: import("zod").ZodOptional<import("zod").ZodString>;
        nextBillingAt: import("zod").ZodOptional<import("zod").ZodString>;
        dunningStartedAt: import("zod").ZodOptional<import("zod").ZodString>;
        dunningAttempt: import("zod").ZodDefault<import("zod").ZodInt>;
        dunningNextRetryAt: import("zod").ZodOptional<import("zod").ZodString>;
        pendingPlanId: import("zod").ZodOptional<import("zod").ZodString>;
        pendingInterval: import("zod").ZodOptional<import("zod").ZodEnum<{
          monthly: "monthly";
          yearly: "yearly";
        }>>;
        metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
      }, import("zod/v4/core").$strip>>;
      page: import("zod").ZodObject<{
        number: import("zod").ZodInt;
        size: import("zod").ZodInt;
        offset: import("zod").ZodInt;
        numberOfElements: import("zod").ZodInt;
        totalElements: import("zod").ZodOptional<import("zod").ZodInt>;
        totalPages: import("zod").ZodOptional<import("zod").ZodInt>;
        isEmpty: import("zod").ZodBoolean;
        isFirst: import("zod").ZodBoolean;
        isLast: import("zod").ZodBoolean;
      }, import("zod/v4/core").$strip>;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Get a subscription by ID.
   */
  readonly getSubscription: import("alepha/server").ActionPrimitiveFn<{
    params: import("zod").ZodObject<{
      id: import("zod").ZodString;
    }, import("zod/v4/core").$strip>;
    response: import("zod").ZodObject<{
      id: PgAttr<PgAttr<import("zod").ZodString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
      version: PgAttr<PgAttr<import("zod").ZodInt, typeof PG_VERSION>, typeof PG_DEFAULT>;
      createdAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
      updatedAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
      organizationId: PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof PG_ORGANIZATION>;
      planId: import("zod").ZodString;
      interval: import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>;
      status: import("zod").ZodEnum<{
        active: "active";
        cancelled: "cancelled";
        expired: "expired";
        past_due: "past_due";
        suspended: "suspended";
        trialing: "trialing";
      }>;
      currentPeriodStart: import("zod").ZodString;
      currentPeriodEnd: import("zod").ZodString;
      trialStart: import("zod").ZodOptional<import("zod").ZodString>;
      trialEnd: import("zod").ZodOptional<import("zod").ZodString>;
      cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
      cancelReason: import("zod").ZodOptional<import("zod").ZodString>;
      cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
      lastPaymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
      lastPaymentAt: import("zod").ZodOptional<import("zod").ZodString>;
      nextBillingAt: import("zod").ZodOptional<import("zod").ZodString>;
      dunningStartedAt: import("zod").ZodOptional<import("zod").ZodString>;
      dunningAttempt: import("zod").ZodDefault<import("zod").ZodInt>;
      dunningNextRetryAt: import("zod").ZodOptional<import("zod").ZodString>;
      pendingPlanId: import("zod").ZodOptional<import("zod").ZodString>;
      pendingInterval: import("zod").ZodOptional<import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>>;
      metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Get aggregated subscription statistics.
   */
  readonly getStats: import("alepha/server").ActionPrimitiveFn<{
    response: import("zod").ZodObject<{
      total: import("zod").ZodInt;
      trialing: import("zod").ZodInt;
      active: import("zod").ZodInt;
      pastDue: import("zod").ZodInt;
      suspended: import("zod").ZodInt;
      cancelled: import("zod").ZodInt;
      expired: import("zod").ZodInt;
      trialConversionRate: import("zod").ZodNumber;
      churnRate: import("zod").ZodNumber;
      byPlan: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
        active: import("zod").ZodInt;
        trialing: import("zod").ZodInt;
        total: import("zod").ZodInt;
      }, import("zod/v4/core").$strip>>;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Get revenue data from recent subscription events.
   */
  readonly getRevenue: import("alepha/server").ActionPrimitiveFn<{
    query: import("zod").ZodObject<{
      days: import("zod").ZodOptional<import("zod").ZodInt>;
    }, import("zod/v4/core").$strip>;
    response: import("zod").ZodObject<{
      total: import("zod").ZodInt;
      count: import("zod").ZodInt;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Get Monthly Recurring Revenue breakdown.
   */
  readonly getMrr: import("alepha/server").ActionPrimitiveFn<{
    response: import("zod").ZodObject<{
      total: import("zod").ZodInt;
      byPlan: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodInt>;
      growth: import("zod").ZodInt;
      newMrr: import("zod").ZodInt;
      expansionMrr: import("zod").ZodInt;
      contractionMrr: import("zod").ZodInt;
      churnMrr: import("zod").ZodInt;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Force a plan change for a subscription (admin action).
   */
  readonly adminChangePlan: import("alepha/server").ActionPrimitiveFn<{
    params: import("zod").ZodObject<{
      id: import("zod").ZodString;
    }, import("zod/v4/core").$strip>;
    body: import("zod").ZodObject<{
      planId: import("zod").ZodString;
      interval: import("zod").ZodOptional<import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>>;
      immediate: import("zod").ZodOptional<import("zod").ZodBoolean>;
    }, import("zod/v4/core").$strip>;
    response: import("zod").ZodObject<{
      id: PgAttr<PgAttr<import("zod").ZodString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
      version: PgAttr<PgAttr<import("zod").ZodInt, typeof PG_VERSION>, typeof PG_DEFAULT>;
      createdAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
      updatedAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
      organizationId: PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof PG_ORGANIZATION>;
      planId: import("zod").ZodString;
      interval: import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>;
      status: import("zod").ZodEnum<{
        active: "active";
        cancelled: "cancelled";
        expired: "expired";
        past_due: "past_due";
        suspended: "suspended";
        trialing: "trialing";
      }>;
      currentPeriodStart: import("zod").ZodString;
      currentPeriodEnd: import("zod").ZodString;
      trialStart: import("zod").ZodOptional<import("zod").ZodString>;
      trialEnd: import("zod").ZodOptional<import("zod").ZodString>;
      cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
      cancelReason: import("zod").ZodOptional<import("zod").ZodString>;
      cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
      lastPaymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
      lastPaymentAt: import("zod").ZodOptional<import("zod").ZodString>;
      nextBillingAt: import("zod").ZodOptional<import("zod").ZodString>;
      dunningStartedAt: import("zod").ZodOptional<import("zod").ZodString>;
      dunningAttempt: import("zod").ZodDefault<import("zod").ZodInt>;
      dunningNextRetryAt: import("zod").ZodOptional<import("zod").ZodString>;
      pendingPlanId: import("zod").ZodOptional<import("zod").ZodString>;
      pendingInterval: import("zod").ZodOptional<import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>>;
      metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Force cancel a subscription (admin action).
   */
  readonly adminCancel: import("alepha/server").ActionPrimitiveFn<{
    params: import("zod").ZodObject<{
      id: import("zod").ZodString;
    }, import("zod/v4/core").$strip>;
    body: import("zod").ZodObject<{
      reason: import("zod").ZodOptional<import("zod").ZodString>;
      immediate: import("zod").ZodOptional<import("zod").ZodBoolean>;
    }, import("zod/v4/core").$strip>;
    response: import("zod").ZodObject<{
      ok: import("zod").ZodBoolean;
      id: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodInt]>>;
      count: import("zod").ZodOptional<import("zod").ZodNumber>;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Reactivate a suspended subscription (admin action).
   */
  readonly adminReactivate: import("alepha/server").ActionPrimitiveFn<{
    params: import("zod").ZodObject<{
      id: import("zod").ZodString;
    }, import("zod/v4/core").$strip>;
    response: import("zod").ZodObject<{
      ok: import("zod").ZodBoolean;
      id: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodInt]>>;
      count: import("zod").ZodOptional<import("zod").ZodNumber>;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Extend the trial period for a trialing subscription (admin action).
   */
  readonly adminExtendTrial: import("alepha/server").ActionPrimitiveFn<{
    params: import("zod").ZodObject<{
      id: import("zod").ZodString;
    }, import("zod/v4/core").$strip>;
    body: import("zod").ZodObject<{
      days: import("zod").ZodInt;
    }, import("zod/v4/core").$strip>;
    response: import("zod").ZodObject<{
      ok: import("zod").ZodBoolean;
      id: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodInt]>>;
      count: import("zod").ZodOptional<import("zod").ZodNumber>;
    }, import("zod/v4/core").$strip>;
  }>;
}
//#endregion
//#region ../../src/api/subscriptions/controllers/SubscriptionController.d.ts
declare class SubscriptionController {
  protected readonly url = "/subscriptions";
  protected readonly group = "subscriptions";
  protected readonly service: SubscriptionService;
  protected readonly config: SubscriptionConfig;
  /**
   * List available subscription plans with pricing.
   */
  readonly getPlans: import("alepha/server").ActionPrimitiveFn<{
    response: import("zod").ZodArray<import("zod").ZodObject<{
      id: import("zod").ZodString;
      name: import("zod").ZodString;
      description: import("zod").ZodOptional<import("zod").ZodString>;
      pricing: import("zod").ZodArray<import("zod").ZodObject<{
        interval: import("zod").ZodEnum<{
          monthly: "monthly";
          yearly: "yearly";
        }>;
        amount: import("zod").ZodInt;
        currency: import("zod").ZodString;
      }, import("zod/v4/core").$strip>>;
      features: import("zod").ZodArray<import("zod").ZodString>;
      limits: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodInt>;
      trial: import("zod").ZodOptional<import("zod").ZodObject<{
        days: import("zod").ZodInt;
        requirePaymentMethod: import("zod").ZodBoolean;
      }, import("zod/v4/core").$strip>>;
      order: import("zod").ZodInt;
    }, import("zod/v4/core").$strip>>;
  }>;
  /**
   * Get the current organization's subscription.
   */
  readonly getMySubscription: import("alepha/server").ActionPrimitiveFn<{
    response: import("zod").ZodObject<{
      id: PgAttr<PgAttr<import("zod").ZodString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
      version: PgAttr<PgAttr<import("zod").ZodInt, typeof PG_VERSION>, typeof PG_DEFAULT>;
      createdAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
      updatedAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
      organizationId: PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof PG_ORGANIZATION>;
      planId: import("zod").ZodString;
      interval: import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>;
      status: import("zod").ZodEnum<{
        active: "active";
        cancelled: "cancelled";
        expired: "expired";
        past_due: "past_due";
        suspended: "suspended";
        trialing: "trialing";
      }>;
      currentPeriodStart: import("zod").ZodString;
      currentPeriodEnd: import("zod").ZodString;
      trialStart: import("zod").ZodOptional<import("zod").ZodString>;
      trialEnd: import("zod").ZodOptional<import("zod").ZodString>;
      cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
      cancelReason: import("zod").ZodOptional<import("zod").ZodString>;
      cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
      lastPaymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
      lastPaymentAt: import("zod").ZodOptional<import("zod").ZodString>;
      nextBillingAt: import("zod").ZodOptional<import("zod").ZodString>;
      dunningStartedAt: import("zod").ZodOptional<import("zod").ZodString>;
      dunningAttempt: import("zod").ZodDefault<import("zod").ZodInt>;
      dunningNextRetryAt: import("zod").ZodOptional<import("zod").ZodString>;
      pendingPlanId: import("zod").ZodOptional<import("zod").ZodString>;
      pendingInterval: import("zod").ZodOptional<import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>>;
      metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Create a new subscription for the current organization.
   */
  readonly subscribe: import("alepha/server").ActionPrimitiveFn<{
    body: import("zod").ZodObject<{
      planId: import("zod").ZodString;
      interval: import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>;
      metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
    }, import("zod/v4/core").$strip>;
    response: import("zod").ZodObject<{
      id: PgAttr<PgAttr<import("zod").ZodString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
      version: PgAttr<PgAttr<import("zod").ZodInt, typeof PG_VERSION>, typeof PG_DEFAULT>;
      createdAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
      updatedAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
      organizationId: PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof PG_ORGANIZATION>;
      planId: import("zod").ZodString;
      interval: import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>;
      status: import("zod").ZodEnum<{
        active: "active";
        cancelled: "cancelled";
        expired: "expired";
        past_due: "past_due";
        suspended: "suspended";
        trialing: "trialing";
      }>;
      currentPeriodStart: import("zod").ZodString;
      currentPeriodEnd: import("zod").ZodString;
      trialStart: import("zod").ZodOptional<import("zod").ZodString>;
      trialEnd: import("zod").ZodOptional<import("zod").ZodString>;
      cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
      cancelReason: import("zod").ZodOptional<import("zod").ZodString>;
      cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
      lastPaymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
      lastPaymentAt: import("zod").ZodOptional<import("zod").ZodString>;
      nextBillingAt: import("zod").ZodOptional<import("zod").ZodString>;
      dunningStartedAt: import("zod").ZodOptional<import("zod").ZodString>;
      dunningAttempt: import("zod").ZodDefault<import("zod").ZodInt>;
      dunningNextRetryAt: import("zod").ZodOptional<import("zod").ZodString>;
      pendingPlanId: import("zod").ZodOptional<import("zod").ZodString>;
      pendingInterval: import("zod").ZodOptional<import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>>;
      metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Change the plan for the current organization's subscription.
   */
  readonly changePlan: import("alepha/server").ActionPrimitiveFn<{
    body: import("zod").ZodObject<{
      planId: import("zod").ZodString;
      interval: import("zod").ZodOptional<import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>>;
      immediate: import("zod").ZodOptional<import("zod").ZodBoolean>;
    }, import("zod/v4/core").$strip>;
    response: import("zod").ZodObject<{
      id: PgAttr<PgAttr<import("zod").ZodString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
      version: PgAttr<PgAttr<import("zod").ZodInt, typeof PG_VERSION>, typeof PG_DEFAULT>;
      createdAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
      updatedAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
      organizationId: PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof PG_ORGANIZATION>;
      planId: import("zod").ZodString;
      interval: import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>;
      status: import("zod").ZodEnum<{
        active: "active";
        cancelled: "cancelled";
        expired: "expired";
        past_due: "past_due";
        suspended: "suspended";
        trialing: "trialing";
      }>;
      currentPeriodStart: import("zod").ZodString;
      currentPeriodEnd: import("zod").ZodString;
      trialStart: import("zod").ZodOptional<import("zod").ZodString>;
      trialEnd: import("zod").ZodOptional<import("zod").ZodString>;
      cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
      cancelReason: import("zod").ZodOptional<import("zod").ZodString>;
      cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
      lastPaymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
      lastPaymentAt: import("zod").ZodOptional<import("zod").ZodString>;
      nextBillingAt: import("zod").ZodOptional<import("zod").ZodString>;
      dunningStartedAt: import("zod").ZodOptional<import("zod").ZodString>;
      dunningAttempt: import("zod").ZodDefault<import("zod").ZodInt>;
      dunningNextRetryAt: import("zod").ZodOptional<import("zod").ZodString>;
      pendingPlanId: import("zod").ZodOptional<import("zod").ZodString>;
      pendingInterval: import("zod").ZodOptional<import("zod").ZodEnum<{
        monthly: "monthly";
        yearly: "yearly";
      }>>;
      metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Cancel the current organization's subscription.
   */
  readonly cancel: import("alepha/server").ActionPrimitiveFn<{
    body: import("zod").ZodObject<{
      reason: import("zod").ZodOptional<import("zod").ZodString>;
      immediate: import("zod").ZodOptional<import("zod").ZodBoolean>;
    }, import("zod/v4/core").$strip>;
    response: import("zod").ZodObject<{
      ok: import("zod").ZodBoolean;
      id: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodInt]>>;
      count: import("zod").ZodOptional<import("zod").ZodNumber>;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Resume a cancelled subscription before the period ends.
   */
  readonly resume: import("alepha/server").ActionPrimitiveFn<{
    response: import("zod").ZodObject<{
      ok: import("zod").ZodBoolean;
      id: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodInt]>>;
      count: import("zod").ZodOptional<import("zod").ZodNumber>;
    }, import("zod/v4/core").$strip>;
  }>;
  /**
   * Get the billing event history for the current organization's subscription.
   */
  readonly getSubscriptionHistory: import("alepha/server").ActionPrimitiveFn<{
    response: import("zod").ZodArray<import("zod").ZodObject<{
      id: PgAttr<PgAttr<import("zod").ZodString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
      createdAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
      subscriptionId: PgAttr<import("zod").ZodString, typeof PG_REF>;
      organizationId: PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof PG_ORGANIZATION>;
      type: import("zod").ZodEnum<{
        activated: "activated";
        cancelled: "cancelled";
        created: "created";
        expired: "expired";
        past_due: "past_due";
        payment_failed: "payment_failed";
        payment_retried: "payment_retried";
        plan_change_scheduled: "plan_change_scheduled";
        plan_changed: "plan_changed";
        reactivated: "reactivated";
        renewed: "renewed";
        resumed: "resumed";
        suspended: "suspended";
        trial_ended: "trial_ended";
        trial_started: "trial_started";
      }>;
      previousStatus: import("zod").ZodOptional<import("zod").ZodString>;
      newStatus: import("zod").ZodOptional<import("zod").ZodString>;
      previousPlanId: import("zod").ZodOptional<import("zod").ZodString>;
      newPlanId: import("zod").ZodOptional<import("zod").ZodString>;
      paymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
      amount: import("zod").ZodOptional<import("zod").ZodInt>;
      currency: import("zod").ZodOptional<import("zod").ZodString>;
      triggeredBy: import("zod").ZodOptional<import("zod").ZodString>;
      userId: import("zod").ZodOptional<import("zod").ZodString>;
      note: import("zod").ZodOptional<import("zod").ZodString>;
    }, import("zod/v4/core").$strip>>;
  }>;
  /**
   * Get the feature and usage limit entitlements for the current organization.
   */
  readonly getEntitlements: import("alepha/server").ActionPrimitiveFn<{
    response: import("zod").ZodObject<{
      planId: import("zod").ZodString;
      planName: import("zod").ZodString;
      status: import("zod").ZodEnum<{
        active: "active";
        cancelled: "cancelled";
        expired: "expired";
        past_due: "past_due";
        suspended: "suspended";
        trialing: "trialing";
      }>;
      features: import("zod").ZodArray<import("zod").ZodString>;
      limits: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodInt>;
      trialEndsAt: import("zod").ZodOptional<import("zod").ZodString>;
      periodEndsAt: import("zod").ZodString;
      cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
    }, import("zod/v4/core").$strip>;
  }>;
}
//#endregion
//#region ../../src/api/subscriptions/jobs/SubscriptionJobs.d.ts
interface EventContext$1 {
  previousStatus?: string;
  newStatus?: string;
  paymentIntentId?: string;
  amount?: number;
  currency?: string;
  triggeredBy?: string;
  note?: string;
}
declare class SubscriptionJobs {
  protected readonly log: import("alepha/logger").Logger;
  protected readonly dateTime: DateTimeProvider;
  protected readonly paymentService: PaymentService;
  protected readonly config: SubscriptionConfig;
  protected readonly subscriptionRepo: import("alepha/orm").Repository<import("zod").ZodObject<{
    id: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_PRIMARY_KEY>, typeof import("alepha/orm").PG_DEFAULT>;
    version: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodInt, typeof import("alepha/orm").PG_VERSION>, typeof import("alepha/orm").PG_DEFAULT>;
    createdAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_CREATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
    updatedAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_UPDATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
    organizationId: import("alepha/orm").PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof import("alepha/orm").PG_ORGANIZATION>;
    planId: import("zod").ZodString;
    interval: import("zod").ZodEnum<{
      monthly: "monthly";
      yearly: "yearly";
    }>;
    status: import("zod").ZodEnum<{
      active: "active";
      cancelled: "cancelled";
      expired: "expired";
      past_due: "past_due";
      suspended: "suspended";
      trialing: "trialing";
    }>;
    currentPeriodStart: import("zod").ZodString;
    currentPeriodEnd: import("zod").ZodString;
    trialStart: import("zod").ZodOptional<import("zod").ZodString>;
    trialEnd: import("zod").ZodOptional<import("zod").ZodString>;
    cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
    cancelReason: import("zod").ZodOptional<import("zod").ZodString>;
    cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
    lastPaymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
    lastPaymentAt: import("zod").ZodOptional<import("zod").ZodString>;
    nextBillingAt: import("zod").ZodOptional<import("zod").ZodString>;
    dunningStartedAt: import("zod").ZodOptional<import("zod").ZodString>;
    dunningAttempt: import("zod").ZodDefault<import("zod").ZodInt>;
    dunningNextRetryAt: import("zod").ZodOptional<import("zod").ZodString>;
    pendingPlanId: import("zod").ZodOptional<import("zod").ZodString>;
    pendingInterval: import("zod").ZodOptional<import("zod").ZodEnum<{
      monthly: "monthly";
      yearly: "yearly";
    }>>;
    metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
  }, import("zod/v4/core").$strip>>;
  protected readonly eventRepo: import("alepha/orm").Repository<import("zod").ZodObject<{
    id: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_PRIMARY_KEY>, typeof import("alepha/orm").PG_DEFAULT>;
    createdAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_CREATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
    subscriptionId: import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_REF>;
    organizationId: import("alepha/orm").PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof import("alepha/orm").PG_ORGANIZATION>;
    type: import("zod").ZodEnum<{
      activated: "activated";
      cancelled: "cancelled";
      created: "created";
      expired: "expired";
      past_due: "past_due";
      payment_failed: "payment_failed";
      payment_retried: "payment_retried";
      plan_change_scheduled: "plan_change_scheduled";
      plan_changed: "plan_changed";
      reactivated: "reactivated";
      renewed: "renewed";
      resumed: "resumed";
      suspended: "suspended";
      trial_ended: "trial_ended";
      trial_started: "trial_started";
    }>;
    previousStatus: import("zod").ZodOptional<import("zod").ZodString>;
    newStatus: import("zod").ZodOptional<import("zod").ZodString>;
    previousPlanId: import("zod").ZodOptional<import("zod").ZodString>;
    newPlanId: import("zod").ZodOptional<import("zod").ZodString>;
    paymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
    amount: import("zod").ZodOptional<import("zod").ZodInt>;
    currency: import("zod").ZodOptional<import("zod").ZodString>;
    triggeredBy: import("zod").ZodOptional<import("zod").ZodString>;
    userId: import("zod").ZodOptional<import("zod").ZodString>;
    note: import("zod").ZodOptional<import("zod").ZodString>;
  }, import("zod/v4/core").$strip>>;
  /**
   * Record a subscription event in the event log.
   */
  protected recordEvent(subscriptionId: string, organizationId: string, type: SubscriptionEventEntity["type"], context?: EventContext$1): Promise<void>;
  /**
   * Creates payment intents for subscriptions due for renewal.
   * Runs hourly.
   */
  readonly billingCycle: import("alepha/api/jobs").JobPrimitive<import("alepha").ZType>;
  /**
   * Retries failed payments on the dunning schedule.
   * Runs hourly.
   */
  readonly dunningRetry: import("alepha/api/jobs").JobPrimitive<import("alepha").ZType>;
  /**
   * Handles trial expirations.
   * Runs hourly.
   */
  readonly trialExpiry: import("alepha/api/jobs").JobPrimitive<import("alepha").ZType>;
  /**
   * Expires cancelled subscriptions that reached period end.
   * Runs hourly.
   */
  readonly expirationSweep: import("alepha/api/jobs").JobPrimitive<import("alepha").ZType>;
  /**
   * Suspends past_due subscriptions where grace period has elapsed.
   * Runs daily at 2 AM.
   */
  readonly gracePeriodSweep: import("alepha/api/jobs").JobPrimitive<import("alepha").ZType>;
  /**
   * Purges old subscription events older than 365 days.
   * Runs daily at 3 AM.
   */
  readonly purgeEvents: import("alepha/api/jobs").JobPrimitive<import("alepha").ZType>;
}
//#endregion
//#region ../../src/api/subscriptions/middleware/$requireLimit.d.ts
/**
 * Middleware that enforces a per-organization usage limit for a resource.
 *
 * Resolves the organization from `args[0].user.organization`, increments the
 * usage counter for the given resource, and throws `ForbiddenError` if the
 * plan limit has been reached.
 * Throws `ForbiddenError` if no organization is present or the limit is exceeded.
 *
 * ```typescript
 * class ApiController {
 *   search = $action({
 *     use: [$requireLimit("api_calls")],
 *     handler: async ({ query }) => { ... },
 *   });
 * }
 * ```
 *
 * @param resource The resource identifier to track (e.g., "api_calls", "exports").
 */
declare const $requireLimit: (resource: string) => Middleware;
//#endregion
//#region ../../src/api/subscriptions/middleware/$requirePlan.d.ts
/**
 * Middleware that gates access to a handler behind a subscription feature flag.
 *
 * Resolves the organization from `args[0].user.organization` and checks whether
 * the organization's current plan includes the given feature.
 * Throws `ForbiddenError` if no organization is present or the feature is not available.
 *
 * ```typescript
 * class ReportController {
 *   generate = $action({
 *     use: [$requirePlan("advanced_reports")],
 *     handler: async ({ user }) => { ... },
 *   });
 * }
 * ```
 *
 * @param feature The feature identifier to check against the plan's feature list.
 */
declare const $requirePlan: (feature: string) => Middleware;
//#endregion
//#region ../../src/api/subscriptions/notifications/SubscriptionNotifications.d.ts
declare class SubscriptionNotifications {
  /**
   * Sent when a trial is ending soon.
   */
  protected readonly trialEnding: import("alepha/api/notifications").NotificationPrimitive<import("zod").ZodObject<{
    planName: import("zod").ZodString;
    trialEndDate: import("zod").ZodString;
    amount: import("zod").ZodString;
    interval: import("zod").ZodString;
  }, import("zod/v4/core").$strip>>;
  /**
   * Sent when a payment fails. Critical notification.
   */
  protected readonly paymentFailed: import("alepha/api/notifications").NotificationPrimitive<import("zod").ZodObject<{
    planName: import("zod").ZodString;
    amount: import("zod").ZodString;
    retryDate: import("zod").ZodOptional<import("zod").ZodString>;
  }, import("zod/v4/core").$strip>>;
  /**
   * Sent when a subscription is suspended due to failed payments. Critical notification.
   */
  protected readonly subscriptionSuspended: import("alepha/api/notifications").NotificationPrimitive<import("zod").ZodObject<{
    planName: import("zod").ZodString;
  }, import("zod/v4/core").$strip>>;
  /**
   * Sent when a subscription is successfully renewed.
   */
  protected readonly subscriptionRenewed: import("alepha/api/notifications").NotificationPrimitive<import("zod").ZodObject<{
    planName: import("zod").ZodString;
    amount: import("zod").ZodString;
    nextBillingDate: import("zod").ZodString;
  }, import("zod/v4/core").$strip>>;
  /**
   * Sent when a subscription plan is changed.
   */
  protected readonly planChanged: import("alepha/api/notifications").NotificationPrimitive<import("zod").ZodObject<{
    oldPlanName: import("zod").ZodString;
    newPlanName: import("zod").ZodString;
    effectiveDate: import("zod").ZodString;
  }, import("zod/v4/core").$strip>>;
  /**
   * Sent when a subscription is cancelled.
   */
  protected readonly cancellationConfirmed: import("alepha/api/notifications").NotificationPrimitive<import("zod").ZodObject<{
    planName: import("zod").ZodString;
    accessUntil: import("zod").ZodOptional<import("zod").ZodString>;
  }, import("zod/v4/core").$strip>>;
}
//#endregion
//#region ../../src/api/subscriptions/schemas/cancelSubscriptionSchema.d.ts
declare const cancelSubscriptionSchema: import("zod").ZodObject<{
  reason: import("zod").ZodOptional<import("zod").ZodString>;
  immediate: import("zod").ZodOptional<import("zod").ZodBoolean>;
}, import("zod/v4/core").$strip>;
type CancelSubscription = Static<typeof cancelSubscriptionSchema>;
//#endregion
//#region ../../src/api/subscriptions/schemas/changePlanSchema.d.ts
declare const changePlanSchema: import("zod").ZodObject<{
  planId: import("zod").ZodString;
  interval: import("zod").ZodOptional<import("zod").ZodEnum<{
    monthly: "monthly";
    yearly: "yearly";
  }>>;
  immediate: import("zod").ZodOptional<import("zod").ZodBoolean>;
}, import("zod/v4/core").$strip>;
type ChangePlan = Static<typeof changePlanSchema>;
//#endregion
//#region ../../src/api/subscriptions/schemas/createSubscriptionSchema.d.ts
/**
 * Public body for the self-service subscribe endpoint.
 *
 * Deliberately does NOT expose `skipTrial` (or a `paymentMethodId`): skipping
 * the trial goes straight to a paid `active` subscription with no captured
 * payment, so it must never be client-controlled. Trusted server-side callers
 * pass `skipTrial` through the `SubscriptionService.subscribe` options after a
 * payment is captured — it is not part of the public request.
 */
declare const createSubscriptionSchema: import("zod").ZodObject<{
  planId: import("zod").ZodString;
  interval: import("zod").ZodEnum<{
    monthly: "monthly";
    yearly: "yearly";
  }>;
  metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
}, import("zod/v4/core").$strip>;
type CreateSubscription = Static<typeof createSubscriptionSchema>;
//#endregion
//#region ../../src/api/subscriptions/schemas/mrrSchema.d.ts
declare const mrrSchema: import("zod").ZodObject<{
  total: import("zod").ZodInt;
  byPlan: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodInt>;
  growth: import("zod").ZodInt;
  newMrr: import("zod").ZodInt;
  expansionMrr: import("zod").ZodInt;
  contractionMrr: import("zod").ZodInt;
  churnMrr: import("zod").ZodInt;
}, import("zod/v4/core").$strip>;
type MrrData = Static<typeof mrrSchema>;
//#endregion
//#region ../../src/api/subscriptions/schemas/planResourceSchema.d.ts
declare const planResourceSchema: import("zod").ZodObject<{
  id: import("zod").ZodString;
  name: import("zod").ZodString;
  description: import("zod").ZodOptional<import("zod").ZodString>;
  pricing: import("zod").ZodArray<import("zod").ZodObject<{
    interval: import("zod").ZodEnum<{
      monthly: "monthly";
      yearly: "yearly";
    }>;
    amount: import("zod").ZodInt;
    currency: import("zod").ZodString;
  }, import("zod/v4/core").$strip>>;
  features: import("zod").ZodArray<import("zod").ZodString>;
  limits: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodInt>;
  trial: import("zod").ZodOptional<import("zod").ZodObject<{
    days: import("zod").ZodInt;
    requirePaymentMethod: import("zod").ZodBoolean;
  }, import("zod/v4/core").$strip>>;
  order: import("zod").ZodInt;
}, import("zod/v4/core").$strip>;
type PlanResource = Static<typeof planResourceSchema>;
//#endregion
//#region ../../src/api/subscriptions/schemas/subscriptionEventResourceSchema.d.ts
declare const subscriptionEventResourceSchema: import("zod").ZodObject<{
  id: PgAttr<PgAttr<import("zod").ZodString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
  createdAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
  subscriptionId: PgAttr<import("zod").ZodString, typeof PG_REF>;
  organizationId: PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof PG_ORGANIZATION>;
  type: import("zod").ZodEnum<{
    activated: "activated";
    cancelled: "cancelled";
    created: "created";
    expired: "expired";
    past_due: "past_due";
    payment_failed: "payment_failed";
    payment_retried: "payment_retried";
    plan_change_scheduled: "plan_change_scheduled";
    plan_changed: "plan_changed";
    reactivated: "reactivated";
    renewed: "renewed";
    resumed: "resumed";
    suspended: "suspended";
    trial_ended: "trial_ended";
    trial_started: "trial_started";
  }>;
  previousStatus: import("zod").ZodOptional<import("zod").ZodString>;
  newStatus: import("zod").ZodOptional<import("zod").ZodString>;
  previousPlanId: import("zod").ZodOptional<import("zod").ZodString>;
  newPlanId: import("zod").ZodOptional<import("zod").ZodString>;
  paymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
  amount: import("zod").ZodOptional<import("zod").ZodInt>;
  currency: import("zod").ZodOptional<import("zod").ZodString>;
  triggeredBy: import("zod").ZodOptional<import("zod").ZodString>;
  userId: import("zod").ZodOptional<import("zod").ZodString>;
  note: import("zod").ZodOptional<import("zod").ZodString>;
}, import("zod/v4/core").$strip>;
type SubscriptionEventResource = Static<typeof subscriptionEventResourceSchema>;
//#endregion
//#region ../../src/api/subscriptions/schemas/subscriptionResourceSchema.d.ts
declare const subscriptionResourceSchema: import("zod").ZodObject<{
  id: PgAttr<PgAttr<import("zod").ZodString, typeof PG_PRIMARY_KEY>, typeof PG_DEFAULT>;
  version: PgAttr<PgAttr<import("zod").ZodInt, typeof PG_VERSION>, typeof PG_DEFAULT>;
  createdAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_CREATED_AT>, typeof PG_DEFAULT>;
  updatedAt: PgAttr<PgAttr<import("zod").ZodString, typeof PG_UPDATED_AT>, typeof PG_DEFAULT>;
  organizationId: PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof PG_ORGANIZATION>;
  planId: import("zod").ZodString;
  interval: import("zod").ZodEnum<{
    monthly: "monthly";
    yearly: "yearly";
  }>;
  status: import("zod").ZodEnum<{
    active: "active";
    cancelled: "cancelled";
    expired: "expired";
    past_due: "past_due";
    suspended: "suspended";
    trialing: "trialing";
  }>;
  currentPeriodStart: import("zod").ZodString;
  currentPeriodEnd: import("zod").ZodString;
  trialStart: import("zod").ZodOptional<import("zod").ZodString>;
  trialEnd: import("zod").ZodOptional<import("zod").ZodString>;
  cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
  cancelReason: import("zod").ZodOptional<import("zod").ZodString>;
  cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
  lastPaymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
  lastPaymentAt: import("zod").ZodOptional<import("zod").ZodString>;
  nextBillingAt: import("zod").ZodOptional<import("zod").ZodString>;
  dunningStartedAt: import("zod").ZodOptional<import("zod").ZodString>;
  dunningAttempt: import("zod").ZodDefault<import("zod").ZodInt>;
  dunningNextRetryAt: import("zod").ZodOptional<import("zod").ZodString>;
  pendingPlanId: import("zod").ZodOptional<import("zod").ZodString>;
  pendingInterval: import("zod").ZodOptional<import("zod").ZodEnum<{
    monthly: "monthly";
    yearly: "yearly";
  }>>;
  metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
}, import("zod/v4/core").$strip>;
type SubscriptionResource = Static<typeof subscriptionResourceSchema>;
//#endregion
//#region ../../src/api/subscriptions/services/BillingService.d.ts
interface PaymentEvent {
  intentId: string;
  amount: number;
  currency: string;
  metadata?: unknown;
}
interface EventContext {
  previousStatus?: string;
  newStatus?: string;
  previousPlanId?: string;
  newPlanId?: string;
  paymentIntentId?: string;
  amount?: number;
  currency?: string;
  triggeredBy?: string;
  userId?: string;
  note?: string;
}
declare class BillingService {
  protected readonly alepha: Alepha;
  protected readonly log: import("alepha/logger").Logger;
  protected readonly dateTime: DateTimeProvider;
  protected readonly subscriptionRepo: import("alepha/orm").Repository<import("zod").ZodObject<{
    id: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_PRIMARY_KEY>, typeof import("alepha/orm").PG_DEFAULT>;
    version: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodInt, typeof import("alepha/orm").PG_VERSION>, typeof import("alepha/orm").PG_DEFAULT>;
    createdAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_CREATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
    updatedAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_UPDATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
    organizationId: import("alepha/orm").PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof import("alepha/orm").PG_ORGANIZATION>;
    planId: import("zod").ZodString;
    interval: import("zod").ZodEnum<{
      monthly: "monthly";
      yearly: "yearly";
    }>;
    status: import("zod").ZodEnum<{
      active: "active";
      cancelled: "cancelled";
      expired: "expired";
      past_due: "past_due";
      suspended: "suspended";
      trialing: "trialing";
    }>;
    currentPeriodStart: import("zod").ZodString;
    currentPeriodEnd: import("zod").ZodString;
    trialStart: import("zod").ZodOptional<import("zod").ZodString>;
    trialEnd: import("zod").ZodOptional<import("zod").ZodString>;
    cancelledAt: import("zod").ZodOptional<import("zod").ZodString>;
    cancelReason: import("zod").ZodOptional<import("zod").ZodString>;
    cancelAtPeriodEnd: import("zod").ZodDefault<import("zod").ZodBoolean>;
    lastPaymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
    lastPaymentAt: import("zod").ZodOptional<import("zod").ZodString>;
    nextBillingAt: import("zod").ZodOptional<import("zod").ZodString>;
    dunningStartedAt: import("zod").ZodOptional<import("zod").ZodString>;
    dunningAttempt: import("zod").ZodDefault<import("zod").ZodInt>;
    dunningNextRetryAt: import("zod").ZodOptional<import("zod").ZodString>;
    pendingPlanId: import("zod").ZodOptional<import("zod").ZodString>;
    pendingInterval: import("zod").ZodOptional<import("zod").ZodEnum<{
      monthly: "monthly";
      yearly: "yearly";
    }>>;
    metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
  }, import("zod/v4/core").$strip>>;
  protected readonly eventRepo: import("alepha/orm").Repository<import("zod").ZodObject<{
    id: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_PRIMARY_KEY>, typeof import("alepha/orm").PG_DEFAULT>;
    createdAt: import("alepha/orm").PgAttr<import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_CREATED_AT>, typeof import("alepha/orm").PG_DEFAULT>;
    subscriptionId: import("alepha/orm").PgAttr<import("zod").ZodString, typeof import("alepha/orm").PG_REF>;
    organizationId: import("alepha/orm").PgAttr<import("zod").ZodOptional<import("zod").ZodString> | import("zod").ZodString, typeof import("alepha/orm").PG_ORGANIZATION>;
    type: import("zod").ZodEnum<{
      activated: "activated";
      cancelled: "cancelled";
      created: "created";
      expired: "expired";
      past_due: "past_due";
      payment_failed: "payment_failed";
      payment_retried: "payment_retried";
      plan_change_scheduled: "plan_change_scheduled";
      plan_changed: "plan_changed";
      reactivated: "reactivated";
      renewed: "renewed";
      resumed: "resumed";
      suspended: "suspended";
      trial_ended: "trial_ended";
      trial_started: "trial_started";
    }>;
    previousStatus: import("zod").ZodOptional<import("zod").ZodString>;
    newStatus: import("zod").ZodOptional<import("zod").ZodString>;
    previousPlanId: import("zod").ZodOptional<import("zod").ZodString>;
    newPlanId: import("zod").ZodOptional<import("zod").ZodString>;
    paymentIntentId: import("zod").ZodOptional<import("zod").ZodString>;
    amount: import("zod").ZodOptional<import("zod").ZodInt>;
    currency: import("zod").ZodOptional<import("zod").ZodString>;
    triggeredBy: import("zod").ZodOptional<import("zod").ZodString>;
    userId: import("zod").ZodOptional<import("zod").ZodString>;
    note: import("zod").ZodOptional<import("zod").ZodString>;
  }, import("zod/v4/core").$strip>>;
  protected readonly paymentService: PaymentService;
  protected readonly config: SubscriptionConfig;
  /**
   * React to successful payment capture.
   * Routes to the appropriate handler based on subscription status.
   */
  protected readonly onPaymentCaptured: import("alepha").HookPrimitive<"payments:captured">;
  /**
   * React to failed payment.
   * Starts or advances the dunning flow.
   */
  protected readonly onPaymentFailed: import("alepha").HookPrimitive<"payments:failed">;
  /**
   * Find a subscription by its last payment intent ID.
   * Returns null if no subscription matches.
   */
  protected findByPaymentIntent(intentId: string): Promise<SubscriptionEntity | null>;
  /**
   * Trial to active transition.
   * Sets the first paid billing period and records activation events.
   */
  protected activate(sub: SubscriptionEntity, event: PaymentEvent): Promise<void>;
  /**
   * Active to active cycle renewal.
   * Applies any pending plan change, then advances the billing period.
   */
  protected renew(sub: SubscriptionEntity, event: PaymentEvent): Promise<void>;
  /**
   * Recover from dunning: past_due to active.
   * Resets all dunning state and records reactivation.
   */
  protected recoverFromDunning(sub: SubscriptionEntity, event: PaymentEvent): Promise<void>;
  /**
   * Reactivate from suspended state after a successful payment.
   * Resets dunning, sets a fresh billing period, and records reactivation.
   */
  protected reactivateFromPayment(sub: SubscriptionEntity, event: PaymentEvent): Promise<void>;
  /**
   * Handle a failed payment: start or advance dunning.
   * Updates dunning state and transitions to past_due if needed.
   */
  protected handlePaymentFailure(sub: SubscriptionEntity, event: PaymentEvent): Promise<void>;
  /**
   * Compute the end of a billing interval from a start date.
   */
  protected computeIntervalEnd(start: string, interval: "monthly" | "yearly"): string;
  /**
   * Record a subscription event in the event log.
   */
  protected recordEvent(subscriptionId: string, organizationId: string, type: SubscriptionEventEntity["type"], context?: EventContext): Promise<void>;
}
//#endregion
//#region ../../src/api/subscriptions/services/UsageService.d.ts
/**
 * The result of a usage check or increment operation.
 */
interface UsageResult {
  /**
   * Whether the operation is allowed given the current usage and limit.
   */
  allowed: boolean;
  /**
   * Current usage count for the period.
   */
  current: number;
  /**
   * The plan limit for the resource. -1 means unlimited.
   */
  limit: number;
  /**
   * Remaining capacity. -1 means unlimited.
   */
  remaining: number;
}
/**
 * Tracks and enforces per-organization resource usage limits.
 *
 * Usage counters are keyed by `organizationId:resource:YYYY-MM` and stored in the cache.
 * Limits are resolved from the organization's current subscription plan.
 */
declare class UsageService {
  protected readonly cache: CacheProvider;
  protected readonly dateTime: DateTimeProvider;
  protected readonly subscriptionService: SubscriptionService;
  /**
   * Increment a resource counter for the current period and return the usage result.
   *
   * @param organizationId The organization to track usage for.
   * @param resource The resource identifier (e.g., "api_calls", "seats").
   * @param amount Amount to increment by (default: 1).
   */
  increment(organizationId: string, resource: string, amount?: number): Promise<UsageResult>;
  /**
   * Get the current usage for a resource without incrementing.
   *
   * @param organizationId The organization to query usage for.
   * @param resource The resource identifier.
   */
  getUsage(organizationId: string, resource: string): Promise<UsageResult>;
  /**
   * Reset all usage counters for an organization.
   *
   * Used at the start of a new billing period.
   *
   * @param organizationId The organization whose counters to reset.
   */
  resetForPeriod(organizationId: string): Promise<void>;
  /**
   * Build the cache key for a usage counter.
   *
   * Format: `organizationId:resource:YYYY-MM`
   */
  protected buildKey(organizationId: string, resource: string): string;
}
//#endregion
//#region ../../src/api/subscriptions/index.d.ts
declare module "alepha" {
  interface Hooks {
    "subscription:created": {
      subscriptionId: string;
      organizationId: string;
      planId: string;
      trial: boolean;
    };
    "subscription:activated": {
      subscriptionId: string;
      organizationId: string;
      planId: string;
    };
    "subscription:renewed": {
      subscriptionId: string;
      organizationId: string;
      planId: string;
      amount: number;
      currency: string;
    };
    "subscription:cancelled": {
      subscriptionId: string;
      organizationId: string;
      planId: string;
      reason?: string;
      immediate: boolean;
    };
    "subscription:expired": {
      subscriptionId: string;
      organizationId: string;
      planId: string;
    };
    "subscription:resumed": {
      subscriptionId: string;
      organizationId: string;
      planId: string;
    };
    "subscription:plan_changed": {
      subscriptionId: string;
      organizationId: string;
      oldPlanId: string;
      newPlanId: string;
      immediate: boolean;
    };
    "subscription:payment_failed": {
      subscriptionId: string;
      organizationId: string;
      planId: string;
      attempt: number;
    };
    "subscription:suspended": {
      subscriptionId: string;
      organizationId: string;
      planId: string;
    };
    "subscription:reactivated": {
      subscriptionId: string;
      organizationId: string;
      planId: string;
    };
    "subscription:trial_ending": {
      subscriptionId: string;
      organizationId: string;
      planId: string;
      endsAt: string;
    };
  }
}
/**
 * Subscription management module — plan-based access control, billing integration,
 * usage limits, and lifecycle events (trial, renewal, cancellation, suspension).
 *
 * Depends on `AlephaPayments` for payment processing — register it in your app
 * alongside this module. Use `SubscriptionConfig` to declare your plans and limits.
 *
 * @module alepha.api.subscriptions
 */
declare const AlephaApiSubscriptions: import("alepha").Service<import("alepha").Module>;
//#endregion
export { $requireLimit, $requirePlan, AdminSubscriptionController, AlephaApiSubscriptions, BillingService, CancelSubscription, ChangePlan, CreateSubscription, Entitlements, MrrData, PlanDefinition, PlanResource, SubscriptionConfig, SubscriptionController, SubscriptionEntity, SubscriptionEventEntity, SubscriptionEventResource, SubscriptionJobs, SubscriptionNotifications, SubscriptionQuery, SubscriptionResource, SubscriptionService, SubscriptionSettings, SubscriptionStats, UsageResult, UsageService, cancelSubscriptionSchema, changePlanSchema, createSubscriptionSchema, entitlementsSchema, mrrSchema, planDefinitionSchema, planResourceSchema, subscriptionEventResourceSchema, subscriptionEvents, subscriptionQuerySchema, subscriptionResourceSchema, subscriptionSettingsSchema, subscriptionStatsSchema, subscriptions };
//# sourceMappingURL=index.d.ts.map