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

export const instanceAgents = pgTable("instance_agents", {
    id: uuid("id").primaryKey().defaultRandom(),

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

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

    name: text("name").notNull(),
    description: text("description"),

    tokenPrefix: text("token_prefix").notNull(),
    tokenHash: text("token_hash").notNull().unique(),

    active: boolean("active").notNull().default(true),

    capabilities: jsonb("capabilities").notNull().default({ scan: true, print: false }),
    scannerNames: jsonb("scanner_names").notNull().default([]),
    printerNames: jsonb("printer_names").notNull().default([]),
    preferredScannerName: text("preferred_scanner_name"),
    scanDefaults: jsonb("scan_defaults").notNull().default({
        format: "pdf",
        resolution: 300,
        mode: "Color",
        source: null,
        postprocess: false,
        postprocessProfile: "document",
    }),

    lastSeenAt: timestamp("last_seen_at", { withTimezone: true }),
    lastDebugInfo: jsonb("last_debug_info"),
})

export type InstanceAgent = typeof instanceAgents.$inferSelect
export type NewInstanceAgent = typeof instanceAgents.$inferInsert
