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

import { tenants } from "./tenants"

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

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

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

    tenant: bigint("tenant", { mode: "number" }).references(() => tenants.id),

    password: text("password"),

    externalId: text("externalId"),

    lastSeen: timestamp("last_seen", { withTimezone: true }),

    // Hier speichern wir den ganzen Payload (RSSI, Heap, IP, etc.)
    lastDebugInfo: jsonb("last_debug_info"),
})

export type Device = typeof devices.$inferSelect
export type NewDevice = typeof devices.$inferInsert
