import { index, jsonb, pgTable, text, timestamp, uuid, } from "drizzle-orm/pg-core";
import { issues } from "./issues.js";
import { organizations } from "./organizations.js";
import { projectWorkspaces } from "./project_workspaces.js";
import { projects } from "./projects.js";
export const executionWorkspaces = pgTable("execution_workspaces", {
    id: uuid("id").primaryKey().defaultRandom(),
    orgId: uuid("org_id").notNull().references(() => organizations.id),
    projectId: uuid("project_id").notNull().references(() => projects.id, { onDelete: "cascade" }),
    projectWorkspaceId: uuid("project_workspace_id").references(() => projectWorkspaces.id, { onDelete: "set null" }),
    sourceIssueId: uuid("source_issue_id").references(() => issues.id, { onDelete: "set null" }),
    mode: text("mode").notNull(),
    strategyType: text("strategy_type").notNull(),
    name: text("name").notNull(),
    status: text("status").notNull().default("active"),
    cwd: text("cwd"),
    repoUrl: text("repo_url"),
    baseRef: text("base_ref"),
    branchName: text("branch_name"),
    providerType: text("provider_type").notNull().default("local_fs"),
    providerRef: text("provider_ref"),
    derivedFromExecutionWorkspaceId: uuid("derived_from_execution_workspace_id")
        .references(() => executionWorkspaces.id, { onDelete: "set null" }),
    lastUsedAt: timestamp("last_used_at", { withTimezone: true }).notNull().defaultNow(),
    openedAt: timestamp("opened_at", { withTimezone: true }).notNull().defaultNow(),
    closedAt: timestamp("closed_at", { withTimezone: true }),
    cleanupEligibleAt: timestamp("cleanup_eligible_at", { withTimezone: true }),
    cleanupReason: text("cleanup_reason"),
    metadata: jsonb("metadata").$type(),
    createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
    updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
}, (table) => ({
    companyProjectStatusIdx: index("execution_workspaces_company_project_status_idx").on(table.orgId, table.projectId, table.status),
    companyProjectWorkspaceStatusIdx: index("execution_workspaces_company_project_workspace_status_idx").on(table.orgId, table.projectWorkspaceId, table.status),
    companySourceIssueIdx: index("execution_workspaces_company_source_issue_idx").on(table.orgId, table.sourceIssueId),
    companyLastUsedIdx: index("execution_workspaces_company_last_used_idx").on(table.orgId, table.lastUsedAt),
    companyBranchIdx: index("execution_workspaces_company_branch_idx").on(table.orgId, table.branchName),
}));
//# sourceMappingURL=execution_workspaces.js.map