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

export const serverData = pgTable(
    "serverData",
    {
        server_id: uuid("server_id").defaultRandom().primaryKey(),
        sName: text("sName").notNull(),
        serverDNS: text("serverDNS"),
        plantToken: text("plantToken"),
        idAddress: text("idAddress"),
        greatPlainsPlantCode: numeric("greatPlainsPlantCode"),
        streetAddress: text("streetAddress"),
        cityState: text("cityState"),
        zipcode: numeric("zipcode"),
        contactEmail: text("contactEmail"),
        contactPhone: text("contactPhone"),
        customerTiAcc: text("customerTiAcc"),
        lstServerPort: numeric("lstServerPort"),
        active: boolean("active").default(true),
        serverLoc: text("serverLoc"),
        oldVersion: text("oldVersion"),
        lastUpdated: timestamp("lastUpdated").defaultNow(),
        shippingHours: text("shippingHours").default(
            '[{"early": "06:30", "late": "23:00"}]'
        ),
        tiPostTime: text("tiPostTime").default('[{"from": "24", "to": "24"}]'),
        otherSettings: jsonb("otherSettings").default([
            { specialInstructions: "something for ti", active: false },
        ]),
        isUpgrading: boolean("isUpgrading").default(false),
    },

    (table) => [
        // uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
        uniqueIndex("plantToken").on(table.plantToken),
    ]
);

export const selectRolesSchema = createSelectSchema(serverData);
