import { defineTable } from "convex/server";
import { v } from "convex/values";

// ── Tables ─────────────────────────────────────────────────────────────

export const customerTables = {
  customers: defineTable({
    prismaId: v.optional(v.string()),
    userId: v.string(),
    organizationId: v.optional(v.string()),
    name: v.string(),
    phone: v.string(),
    email: v.optional(v.string()),
    notes: v.optional(v.string()),
    createdAt: v.number(),
    updatedAt: v.number(),
    source: v.optional(v.string()),
  })
    .index("by_createdAt", ["createdAt"])
    .index("by_phone", ["phone"])
    .index("by_userId", ["userId"])
    .index("by_userId_name", ["userId", "name"])
    .index("by_userId_phone", ["userId", "phone"])
    .index("by_organizationId", ["organizationId"])
    .index("by_organizationId_phone", ["organizationId", "phone"])
    .index("by_organizationId_name", ["organizationId", "name"]),
};
