import { type Kysely } from 'kysely';
import type { Environment as EngineEnvironment } from '@kici-dev/engine';
import type { Database, Environment } from '../db/types.js';
/** Thrown by `delete` when pending held runs reference the environment. */
export declare class EnvironmentDeleteBlockedError extends Error {
    readonly pendingCount: number;
    constructor(pendingCount: number);
}
/**
 * Map a DB environment row (snake_case) to the engine Environment type (camelCase).
 *
 * Kysely returns JSONB columns as strings; this function parses them into arrays.
 */
export declare function toEnvironment(row: Environment): EngineEnvironment;
/** Fields accepted when creating an environment. */
export interface EnvironmentCreateInput {
    name: string;
    type?: 'fixed' | 'glob';
    globPattern?: string | null;
    branchRestrictions?: string[];
    triggerTypeFilters?: string[];
    repoPatterns?: string[];
    concurrencyLimit?: number | null;
    concurrencyStrategy?: 'queue' | 'cancel-pending';
    concurrencyTimeoutMs?: number;
    requiredReviewers?: string[] | null;
    waitTimerSeconds?: number | null;
    holdExpirySeconds?: number;
    minimumTrust?: 'known' | 'trusted' | null;
    allowLocalExecution?: boolean;
    enabled?: boolean;
    createdBy?: string | null;
}
/** Fields accepted when updating an environment. */
export interface EnvironmentUpdateInput {
    name?: string;
    type?: 'fixed' | 'glob';
    globPattern?: string | null;
    branchRestrictions?: string[];
    triggerTypeFilters?: string[];
    repoPatterns?: string[];
    concurrencyLimit?: number | null;
    concurrencyStrategy?: 'queue' | 'cancel-pending';
    concurrencyTimeoutMs?: number;
    requiredReviewers?: string[] | null;
    waitTimerSeconds?: number | null;
    holdExpirySeconds?: number;
    minimumTrust?: 'known' | 'trusted' | null;
    allowLocalExecution?: boolean;
    enabled?: boolean;
}
/**
 * Data access layer for environments.
 */
export declare class EnvironmentStore {
    private readonly db;
    constructor(db: Kysely<Database>);
    /** List all environments for an org, ordered by name. */
    list(orgId: string): Promise<Environment[]>;
    /** Get a single environment by org + id. Returns null if not found. */
    get(orgId: string, id: string): Promise<Environment | null>;
    /** Get a single environment by org + name. Returns null if not found. */
    getByName(orgId: string, name: string): Promise<Environment | null>;
    /** Create a new environment. Returns the created row. */
    create(orgId: string, data: EnvironmentCreateInput): Promise<Environment>;
    /** Update an environment. Returns the updated row, or null if not found. */
    update(orgId: string, id: string, updates: EnvironmentUpdateInput): Promise<Environment | null>;
    /**
     * Delete an environment.
     *
     * Bindings, variables, and source overrides cascade away via their FK.
     * Terminal held-run history survives with a null `environment_id` (the FK
     * uses ON DELETE SET NULL). Pending held runs still reference the
     * environment, so deletion is blocked with `EnvironmentDeleteBlockedError`
     * until they are approved or rejected.
     */
    delete(orgId: string, id: string): Promise<boolean>;
    /**
     * Match an environment name against org environments.
     *
     * First tries exact name match (for fixed environments).
     * If no exact match, scans glob-type environments and uses picomatch.
     * Returns the first matching environment or null.
     */
    matchEnvironment(orgId: string, name: string): Promise<Environment | null>;
}
//# sourceMappingURL=environment-store.d.ts.map