import { pgTable, text, timestamp, integer, boolean } from "drizzle-orm/pg-core";

export const BOOTSTRAP_JOB_STATES = [
  "awaiting_payment",
  "provisioning",
  "ready",
  "failed",
] as const;

export type BootstrapJobState = (typeof BOOTSTRAP_JOB_STATES)[number];

export const bootstrapJobs = pgTable("bootstrap_jobs", {
  id: text("id").primaryKey(),
  state: text("state").$type<BootstrapJobState>().notNull().default("awaiting_payment"),

  amountSats: integer("amount_sats").notNull(),
  paymentHash: text("payment_hash").notNull(),
  paymentRequest: text("payment_request").notNull(),

  dropletId: text("droplet_id"),
  nodeIp: text("node_ip"),
  tailscaleHostname: text("tailscale_hostname"),
  lnbitsUrl: text("lnbits_url"),
  sshPrivateKey: text("ssh_private_key"),
  sshKeyDelivered: boolean("ssh_key_delivered").notNull().default(false),

  errorMessage: text("error_message"),

  createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
  updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
});

export type BootstrapJob = typeof bootstrapJobs.$inferSelect;
