import { teamTable } from "../team/team.sql.js";
import { pgTable, varchar } from "drizzle-orm/pg-core";
import { id, timestamps, ulid } from "../drizzle/types.js";

export const apiAppTable = pgTable("api_app", {
  ...id,
  ...timestamps,
  name: varchar("name", { length: 255 }).notNull(),
  secret: varchar("secret", { length: 255 }).notNull(),
  redirectURI: varchar("redirect", { length: 255 }).notNull(),
  teamID: ulid("team_id")
    .references(() => teamTable.id, {
      onDelete: "cascade",
    })
    .notNull(),
});

export const apiPersonalTokenTable = pgTable("api_personal_token", {
  ...id,
  ...timestamps,
  token: varchar("token", { length: 255 }).notNull(),
  teamID: ulid("team_id")
    .references(() => teamTable.id, {
      onDelete: "cascade",
    })
    .notNull(),
});
