import { z } from "zod/v4";
import { Examples } from "../examples.js";
import { userTable } from "../user/user.sql.js";
import { timestamps, ulid, utc } from "../drizzle/types.js";
import { pgTable, varchar, json } from "drizzle-orm/pg-core";

export const Limitations = z.object({
  isLimited: z.boolean().meta({
    description: "Whether the account has limited functionality",
    example: Examples.SteamAccount.limitations.isLimited,
  }),
  tradeBanState: z.string().meta({
    description: "The current trade ban status",
    example: Examples.SteamAccount.limitations.tradeBanState,
  }),
  isVacBanned: z.boolean().meta({
    description: "Whether the account is VAC banned",
    example: Examples.SteamAccount.limitations.isVacBanned,
  }),
  visibilityState: z.number().meta({
    description: "The visibility state of the profile",
    example: Examples.SteamAccount.limitations.visibilityState,
  }),
  privacyState: z.string().meta({
    description: "The privacy state of the profile",
    example: Examples.SteamAccount.limitations.privacyState,
  }),
});

export type Limitations = z.infer<typeof Limitations>;

export const steamTable = pgTable("steam_accounts", {
  ...timestamps,
  id: varchar("id", { length: 255 }).primaryKey().notNull(),
  ownerID: ulid("owner_id")
    .references(() => userTable.id, {
      onDelete: "cascade",
    })
    .notNull(),
  memberSince: utc("member_since").notNull(),
  name: varchar("name", { length: 255 }).notNull(),
  lastSyncedAt: utc("last_synced_at").notNull(),
  realName: varchar("real_name", { length: 255 }),
  profileUrl: varchar("profile_url", { length: 255 }),
  avatarHash: varchar("avatar_hash", { length: 255 }).notNull(),
  limitations: json("limitations").$type<Limitations>().notNull(),
});
