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

// The schema is normally optional, but Convex Auth
// requires indexes defined on `authTables`.
// The schema provides more precise TypeScript types.
export default defineSchema({
  ...authTables,
  users: defineTable({
    name: v.optional(v.string()),
    image: v.optional(v.string()),
    email: v.optional(v.string()),
    currentStatusId: v.optional(v.id('statuses')),
    lunchTime: v.optional(v.string()),
    emailVerificationTime: v.optional(v.number()),
    phone: v.optional(v.string()),
    phoneVerificationTime: v.optional(v.number()),
    isAnonymous: v.optional(v.boolean()),
  })
    .index('email', ['email'])
    .index('phone', ['phone']),
  statuses: defineTable({
    userId: v.id('users'),
    message: v.string(),
    updatedAt: v.number(),
    updatedBy: v.optional(v.id('users')),
  })
    .index('by_user', ['userId'])
    .index('by_user_updatedAt', ['userId', 'updatedAt']),
});
