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

export const opendockApt = pgTable(
	"opendock_apt",
	{
		id: uuid("id").defaultRandom().primaryKey(),
		release: integer("release").notNull().unique("opendock_apt_release_unique"),
		openDockAptId: text("open_dock_apt_id").notNull(),
		status: text("status").default("active"),
		appointment: jsonb("appointment").notNull().default([]),
		upd_date: timestamp("upd_date", { withTimezone: true })
			.notNull()
			.defaultNow(),
		createdAt: timestamp("created_at", { withTimezone: true })
			.notNull()
			.defaultNow(),
	},
	(table) => ({
		openDockAptIdIdx: index("opendock_apt_opendock_id_idx").on(
			table.openDockAptId,
		),
	}),
);

export const opendockAptSchema = createSelectSchema(opendockApt);
export const newOpendockAptSchema = createInsertSchema(opendockApt);

export type OpendockApt = z.infer<typeof opendockAptSchema>;
export type NewOpendockApt = z.infer<typeof newOpendockAptSchema>;
