import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
import { AnySQLiteTable, AnySQLiteColumn, BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
import { I as IntakeAnswerValue, b as IntakeGraph } from '../model-Bzi5i63l.js';
import { I as IntakePayload } from '../completion-Kaqp_tWk.js';

/** A product table referenced by FK — only the `id` column is touched. */
type IntakeParentTable = AnySQLiteTable & {
    id: AnySQLiteColumn;
};
interface CreateIntakeTablesOptions {
    /** The product's user table — user-intake rows reference `userTable.id`. */
    userTable: IntakeParentTable;
    /**
     * The product's workspace table — project-intake rows reference
     * `workspaceTable.id`. OPTIONAL: omit it for a single-user / non-workspace
     * app that wants per-user onboarding only. When omitted, no `projectIntake`
     * table is created.
     */
    workspaceTable?: IntakeParentTable;
}
declare function createUserIntakeTable(userTable: IntakeParentTable): drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
    name: "user_intake";
    schema: undefined;
    columns: {
        id: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "id";
            tableName: "user_intake";
            dataType: "string";
            columnType: "SQLiteText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: true;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {
            length: number | undefined;
        }>;
        userId: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "user_id";
            tableName: "user_intake";
            dataType: "string";
            columnType: "SQLiteText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {
            length: number | undefined;
        }>;
        graphId: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "graph_id";
            tableName: "user_intake";
            dataType: "string";
            columnType: "SQLiteText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {
            length: number | undefined;
        }>;
        payload: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "payload";
            tableName: "user_intake";
            dataType: "json";
            columnType: "SQLiteTextJson";
            data: unknown;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        completedAt: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "completed_at";
            tableName: "user_intake";
            dataType: "date";
            columnType: "SQLiteTimestamp";
            data: Date;
            driverParam: number;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "created_at";
            tableName: "user_intake";
            dataType: "date";
            columnType: "SQLiteTimestamp";
            data: Date;
            driverParam: number;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        updatedAt: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "updated_at";
            tableName: "user_intake";
            dataType: "date";
            columnType: "SQLiteTimestamp";
            data: Date;
            driverParam: number;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
    };
    dialect: "sqlite";
}>;
declare function createProjectIntakeTable(workspaceTable: IntakeParentTable): drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
    name: "project_intake";
    schema: undefined;
    columns: {
        id: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "id";
            tableName: "project_intake";
            dataType: "string";
            columnType: "SQLiteText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: true;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {
            length: number | undefined;
        }>;
        workspaceId: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "workspace_id";
            tableName: "project_intake";
            dataType: "string";
            columnType: "SQLiteText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {
            length: number | undefined;
        }>;
        graphId: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "graph_id";
            tableName: "project_intake";
            dataType: "string";
            columnType: "SQLiteText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {
            length: number | undefined;
        }>;
        payload: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "payload";
            tableName: "project_intake";
            dataType: "json";
            columnType: "SQLiteTextJson";
            data: unknown;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        completedAt: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "completed_at";
            tableName: "project_intake";
            dataType: "date";
            columnType: "SQLiteTimestamp";
            data: Date;
            driverParam: number;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "created_at";
            tableName: "project_intake";
            dataType: "date";
            columnType: "SQLiteTimestamp";
            data: Date;
            driverParam: number;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        updatedAt: drizzle_orm_sqlite_core.SQLiteColumn<{
            name: "updated_at";
            tableName: "project_intake";
            dataType: "date";
            columnType: "SQLiteTimestamp";
            data: Date;
            driverParam: number;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
    };
    dialect: "sqlite";
}>;
/**
 * Build the intake tables wired to the product's tables. Always returns
 * `userIntake`; returns `projectIntake` only when `workspaceTable` is passed.
 * The return type carries `projectIntake?` so a consumer that passes no
 * workspace table cannot reference a table that does not exist.
 */
declare function createIntakeTables<O extends CreateIntakeTablesOptions>(opts: O): IntakeTables<O>;
type UserIntakeTable = ReturnType<typeof createUserIntakeTable>;
type ProjectIntakeTable = ReturnType<typeof createProjectIntakeTable>;
/**
 * The tables returned for a given options shape: `projectIntake` is present in
 * the type exactly when `workspaceTable` was provided.
 */
type IntakeTables<O extends CreateIntakeTablesOptions> = O extends {
    workspaceTable: IntakeParentTable;
} ? {
    userIntake: UserIntakeTable;
    projectIntake: ProjectIntakeTable;
} : {
    userIntake: UserIntakeTable;
    projectIntake?: ProjectIntakeTable;
};
/** The union table shape, for code that handles either scope generically. */
type AnyIntakeTables = {
    userIntake: UserIntakeTable;
    projectIntake?: ProjectIntakeTable;
};
type UserIntakeRow = UserIntakeTable['$inferSelect'];
type ProjectIntakeRow = ProjectIntakeTable['$inferSelect'];

/**
 * Drizzle-backed store over the tables from `createIntakeTables`. One store
 * builder per scope: `createUserIntakeStore` (keyed on userId) and
 * `createProjectIntakeStore` (keyed on workspaceId). Each returns the same
 * three-method surface — `get` / `save` / `complete` — so the api handlers and
 * the UI talk to one shape regardless of scope.
 *
 * Works against any SQLite drizzle driver (better-sqlite3, D1, libsql): the
 * builders are awaited, never `.run()`/`.all()`, so sync and async drivers
 * behave identically.
 *
 * Validation is fail-loud and pure (from the `./intakes` leaf). `save` runs
 * `validateAnswer` before writing, so an invalid answer can never enter the
 * payload; `complete` runs `payloadComplete` and refuses to stamp an
 * incomplete (or stale-graph) intake — it throws a typed `IntakeError` rather
 * than silently writing a half-finished onboarding state.
 *
 * `getProjectIntakeStore` pins `workspaceId` in every WHERE clause; RBAC runs
 * in the route before the store is built, but the scope key is enforced here
 * too, so a leaked id can never read or write across the boundary.
 *
 * Imports `drizzle-orm`, so this is a subpath, never re-exported from root.
 */

/** Any SQLite drizzle database — `any` erases driver-specific generics so
 *  better-sqlite3, D1, and libsql handles all fit. */
type IntakeDatabase = BaseSQLiteDatabase<'sync' | 'async', any, any>;
/** A loaded intake: the payload plus whether it is complete against the graph. */
interface IntakeState {
    payload: IntakePayload;
    completed: boolean;
    completedAt: Date | null;
}
type IntakeErrorCode = 'invalid-answer' | 'unknown-question' | 'incomplete' | 'stale-graph';
/** Thrown by store mutations on a refused write — callers map it to a 4xx. */
declare class IntakeError extends Error {
    readonly code: IntakeErrorCode;
    constructor(code: IntakeErrorCode, message: string);
}
/** The three-method store surface, identical for both scopes. */
interface IntakeStore {
    /** Load the current intake, or seed an empty payload when none exists yet. */
    get(): Promise<IntakeState>;
    /** Validate and persist one answer; returns the updated state. */
    save(questionId: string, value: IntakeAnswerValue): Promise<IntakeState>;
    /** Stamp the intake complete; throws IntakeError when not yet completable. */
    complete(): Promise<IntakeState>;
}
interface CreateUserIntakeStoreOptions {
    db: IntakeDatabase;
    /** The user-intake table from createIntakeTables. */
    table: UserIntakeTable;
    /** The intake definition this store collects answers against. */
    graph: IntakeGraph;
    /** The user whose onboarding this is. */
    userId: string;
}
/** Build the per-user onboarding store, scoped to one userId. */
declare function createUserIntakeStore(opts: CreateUserIntakeStoreOptions): IntakeStore;
interface CreateProjectIntakeStoreOptions {
    db: IntakeDatabase;
    /** The project-intake table from createIntakeTables (workspace scope). */
    table: ProjectIntakeTable;
    graph: IntakeGraph;
    /** The workspace this intake is attached to. */
    workspaceId: string;
}
/** Build the per-project store, scoped to one workspaceId. */
declare function createProjectIntakeStore(opts: CreateProjectIntakeStoreOptions): IntakeStore;

export { type AnyIntakeTables, type CreateIntakeTablesOptions, type CreateProjectIntakeStoreOptions, type CreateUserIntakeStoreOptions, type IntakeDatabase, IntakeError, type IntakeErrorCode, type IntakeParentTable, type IntakeState, type IntakeStore, type IntakeTables, type ProjectIntakeRow, type ProjectIntakeTable, type UserIntakeRow, type UserIntakeTable, createIntakeTables, createProjectIntakeStore, createUserIntakeStore };
