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

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

export const expenseTables = {
  expense_categories: defineTable({
    prismaId: v.optional(v.string()),
    userId: v.string(),
    name: v.string(),
    nameAr: v.optional(v.string()),
    color: v.string(),
    icon: v.optional(v.string()),
    sortOrder: v.number(),
    createdAt: v.number(),
    updatedAt: v.number(),
  })
    .index("by_userId", ["userId"])
    .index("by_userId_sortOrder", ["userId", "sortOrder"]),

  expenses: defineTable({
    prismaId: v.optional(v.string()),
    userId: v.string(),
    categoryId: v.string(),
    amount: v.number(),
    currency: v.string(),
    vendor: v.optional(v.string()),
    description: v.optional(v.string()),
    date: v.number(),
    receiptUrl: v.optional(v.string()),
    isRecurring: v.boolean(),
    recurringFrequency: v.optional(v.string()),
    tags: v.array(v.string()),
    notes: v.optional(v.string()),
    createdAt: v.number(),
    updatedAt: v.number(),
  })
    .index("by_userId", ["userId"])
    .index("by_userId_date", ["userId", "date"])
    .index("by_userId_categoryId", ["userId", "categoryId"])
    .index("by_categoryId", ["categoryId"])
    .index("by_date", ["date"]),
};
