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

export const rfidTags = pgTable(
    "rfidTags",
    {
        rfidTag_id: uuid("rfidTag_id").defaultRandom().primaryKey(),
        tagHex: text("tagHex"),
        tag: text("tag"),
        lastRead: timestamp("lastRead").defaultNow(), // cahnge this and hope we dont loose the data.
        counts: jsonb("counts").default([]), // example [{area: Line3.2, count: 1}, {area: line3.1, count: 6}]
        lastareaIn: text("lastareaIn").notNull(),
        runningNumber: integer("runningNumber"),
        antenna: integer("antenna"),
        tagStrength: integer("tagStrength"),
        created_at: timestamp("created_at").defaultNow(),
    },
    (table) => [
        // uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
        uniqueIndex("tagHex").on(table.tagHex),
    ]
);

// Schema for inserting a user - can be used to validate API requests
// export const insertRolesSchema = createInsertSchema(rfidTags, {
//     tagHex: z.string().min(3, {message: "Tag Should have more than 3 characters"}),
// });
// Schema for selecting a Expenses - can be used to validate API responses
export const selectRolesSchema = createSelectSchema(rfidTags);
