import { authTables } from '@convex-dev/auth/server';
import { defineSchema, defineTable } from 'convex/server';
import { v } from 'convex/values';

const applicationTables = {
  /*
   * Below is the users table definition from authTables
   * You can add additional fields here. You can also remove
   * the users table here & create a 'profiles' table if you
   * prefer to keep auth data separate from application data.
   */
  users: defineTable({
    name: v.optional(v.string()),
    image: v.optional(v.string()),
    email: v.optional(v.string()),
    emailVerificationTime: v.optional(v.number()),
    phone: v.optional(v.string()),
    phoneVerificationTime: v.optional(v.number()),
    isAnonymous: v.optional(v.boolean()),
    /* Fields below here are custom & not defined in authTables */
    isAdmin: v.optional(v.boolean()),
    themePreference: v.optional(
      v.union(v.literal('light'), v.literal('dark'), v.literal('system')),
    ),
  })
    .index('email', ['email'])
    .index('phone', ['phone'])
    /* Indexes below here are custom & not defined in authTables */
    .index('name', ['name']),
};

export default defineSchema({
  ...authTables,
  ...applicationTables,
});
