import { v } from "convex/values";
import { query } from "./_generated/server";

/**
 * Listar todas as roles
 */
export const listar = query({
  args: {},
  handler: async (ctx) => {
    return await ctx.db.query("roles").collect();
  },
});

/**
 * Buscar role por ID
 */
export const buscarPorId = query({
  args: {
    roleId: v.id("roles"),
  },
  returns: v.union(
    v.object({
      _id: v.id("roles"),
      nome: v.string(),
      descricao: v.string(),
      nivel: v.number(),
      setor: v.optional(v.string()),
    }),
    v.null()
  ),
  handler: async (ctx, args) => {
    return await ctx.db.get(args.roleId);
  },
});

