import { date, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import z from "zod";
import { forkliftCompanies } from "./forkliftLeaseCompanys.js";

export const leases = pgTable("leases", {
	id: uuid("id").defaultRandom().primaryKey(),
	leaseNumber: text("lease_number").unique().notNull(),
	companyId: uuid("company_id").references(() => forkliftCompanies.id),
	startDate: date("start_date"),
	endDate: date("end_date"),
	leaseLink: text("lease_link"),
	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"),
});
export const selectLeasesDataSchema = createSelectSchema(leases);

export const insertLeasesCompanySchema = createInsertSchema(leases).extend({
	leaseNumber: z.string().min(3),
	// zipcode: z
	//     .string()
	//     .regex(/^\d{5}$/)
	//     .optional(),
});
