import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as dockScans from "./schema/dockdoor.scans.schema.js";
import * as logs from "./schema/logs.schema.js";
import * as opendockAVCheck from "./schema/opendock_articleSetup.js";
import * as prodAuditLogId from "./schema/prodAuditlog.lastProcessed.schema.js";
import * as prodAuditLog from "./schema/prodAuditlog.schema.js";
import * as scanUserSchema from "./schema/scanUsers.js";
import * as settingsSchema from "./schema/settings.schema.js";

const dbURL = `postgres://${process.env.DATABASE_USER}:${process.env.DATABASE_PASSWORD}@${process.env.DATABASE_HOST}:${process.env.DATABASE_PORT}/${process.env.DATABASE_DB}`;

const queryClient = postgres(dbURL, {
	max: 10,
	idle_timeout: 60,
	connect_timeout: 30,
	max_lifetime: 1000 * 6 * 5,
	onnotice: (n) => {
		console.info("PG notice: ", n.message);
	},
});

//export const db = drizzle({ client: queryClient });

export const db = drizzle(queryClient, {
	schema: {
		...scanUserSchema,
		...settingsSchema,
		...opendockAVCheck,
		...logs,
		...dockScans,
		...prodAuditLogId,
		...prodAuditLog,
	},
});
