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

export const appStats = pgTable("app_stats", {
	id: text("id").primaryKey().default("primary"),
	currentBuild: integer("current_build").notNull().default(1),
	lastBuildAt: timestamp("last_build_at", { withTimezone: true }),
	lastDeployAt: timestamp("last_deploy_at", { withTimezone: true }),
	building: boolean("building").notNull().default(false),
	updating: boolean("updating").notNull().default(false),
	lastUpdated: timestamp("last_updated", { withTimezone: true }).defaultNow(),
	meta: jsonb("meta").$type<Record<string, unknown>>().default({}),
});

export const appStatsSchema = createSelectSchema(appStats);
export const newAppStatsSchema = createInsertSchema(appStats, {});

export type AppStats = z.infer<typeof appStatsSchema>;
export type NewAppStats = z.infer<typeof newAppStatsSchema>;
