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

export const alplaPurchaseHistory = pgTable("alpla_purchase_history", {
	id: uuid("id").defaultRandom().primaryKey(),
	apo: integer("apo"),
	revision: integer("revision"),
	confirmed: integer("confirmed"),
	status: integer("status"),
	statusText: text("status_text"),
	journalNum: integer("journal_num"),
	add_date: timestamp("add_date", { withTimezone: true }).defaultNow(),
	add_user: text("add_user"),
	upd_user: text("upd_user"),
	upd_date: timestamp("upd_date", { withTimezone: true }).defaultNow(),
	remark: text("remark"),
	approvedStatus: text("approved_status").default("new"),
	position: jsonb("position").default([]),
	createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
	updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
});

export const alplaPurchaseHistorySchema =
	createSelectSchema(alplaPurchaseHistory);
export const newAlplaPurchaseHistorySchema =
	createInsertSchema(alplaPurchaseHistory);

export type AlplaPurchaseHistory = z.infer<typeof alplaPurchaseHistorySchema>;
export type NewAlplaPurchaseHistory = z.infer<
	typeof newAlplaPurchaseHistorySchema
>;
