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

export const qualityRequest = pgTable(
	"qualityRequest",
	{
		request_id: uuid("request_id").defaultRandom().primaryKey(),
		article: numeric("article"),
		description: text("description"),
		runningNr: text("runningNr"),
		lotNr: numeric("lotNr"),
		warehouseAtRequest: text("warehouseAtRequest"),
		locationAtRequest: text("locationAtRequest"),
		warehouseMovedTo: text("warehouseMovedTo"),
		locationMovedTo: text("locationMovedTo"),
		durationToMove: integer("durationToMove"),
		qualityDurationToInspect: integer("qualityDurationToInspect"),
		returnDurationToInspect: integer("returnDurationToInspect"),
		locationDropOff: text("locationDropOff"),
		palletStatus: integer("palletStatus"),
		palletStatusText: text("palletStatusText"),
		palletRequest: integer("palletRequest"),
		priority: integer("priority").default(4), // 1,2,3,4
		add_date: timestamp("add_date").defaultNow(),
		add_user: text("add_user").default("LST"),
		upd_date: timestamp("upd_date").defaultNow(),
		upd_user: text("upd_user").default("LST"),
		comments: text("comments")
	},
	(table) => [
		// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
		// uniqueIndex("role_name").on(table.name),
	],
);

// Schema for inserting a user - can be used to validate API requests
// export const insertRolesSchema = createInsertSchema(roles, {
//     name: z.string().min(3, {message: "Role name must be more than 3 letters"}),
// });
// Schema for selecting a Expenses - can be used to validate API responses
export const selectRolesSchema = createSelectSchema(qualityRequest);
