import { v } from "convex/values";

import { query } from "./_generated/server";
import { requireProjectMember } from "./authz";

export const list = query({
  args: { projectId: v.id("projects") },
  handler: async (ctx, args) => {
    try {
      await requireProjectMember(ctx, args.projectId);
    } catch {
      return [];
    }
    return await ctx.db
      .query("projectArtifacts")
      .withIndex("by_project", (q) => q.eq("projectId", args.projectId))
      .take(25);
  },
});
