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

export const rfidReaders = pgTable(
    "rfidReaders",
    {
        rfidReader_id: uuid("rfidReader_id").defaultRandom().primaryKey(),
        reader: text("reader"),
        readerIP: text("readerIP"),
        lastHeartBeat: timestamp("lastHeartBeat").defaultNow(),
        lastTrigger: timestamp("lastTrigger").defaultNow(),
        lastTriggerGood: boolean("lastTiggerGood").default(true),
        active: boolean("active").default(true),
        lastTagScanned: text("lastTagScanned"),
        goodReads: integer("goodReads").default(0),
        badReads: integer("badReads").default(0),
    },
    (table) => [
        // uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
        uniqueIndex("reader").on(table.reader),
    ]
);

// 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(rfidReaders);
