import type { SupabaseClient } from "@supabase/supabase-js";

export async function logTeamAudit(
  supabase: SupabaseClient,
  input: {
    teamId: string | null | undefined;
    actorId: string | null | undefined;
    action: string;
    entityType:
      | "team"
      | "member"
      | "invite"
      | "project"
      | "task"
      | "note"
      | "event"
      | "comment";
    entityId?: string | null;
    title: string;
    details?: Record<string, unknown>;
  }
) {
  if (!input.teamId) return;

  await supabase.from("team_audit_log").insert({
    team_id: input.teamId,
    actor_id: input.actorId || null,
    action: input.action,
    entity_type: input.entityType,
    entity_id: input.entityId || null,
    title: input.title,
    details: input.details || {},
  });
}
