import {
	boolean,
	jsonb,
	pgTable,
	text,
	timestamp,
	uuid,
} from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import type { z } from "zod";

export const logs = pgTable("logs", {
	id: uuid("id").defaultRandom().primaryKey(),
	level: text("level"),
	module: text("module").notNull(),
	subModule: text("subModule"),
	message: text("message").notNull(),
	stack: jsonb("stack").default([]),
	checked: boolean("checked").default(false),
	hostname: text("hostname"),
	createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
});

export const logSchema = createSelectSchema(logs);
export const newLogSchema = createInsertSchema(logs);

export type Log = z.infer<typeof logSchema>;
export type NewLog = z.infer<typeof newLogSchema>;
