"use server"; import { revalidatePath } from "next/cache"; import { createClient } from "@/lib/supabase/server"; type ActionResult = { success: boolean; error?: string }; export type ReorgMovePayload = { kind: "emp" | "team" | "abt" | "dept"; label: string; employee_ids: string[]; target_team_id: string; }; export async function applyReorg(payload: { name: string; effective_date: string; moves: ReorgMovePayload[]; }): Promise { const supabase = await createClient(); const { data, error } = await supabase.rpc("apply_reorg", { payload }); if (error) return { success: false, error: error.message }; revalidatePath("/orgchart"); revalidatePath("/employees"); revalidatePath("/"); return { success: true, scenarioId: data as string }; } export async function undoReorg(payload: { scenario_id: string }): Promise { const supabase = await createClient(); const { error } = await supabase.rpc("undo_reorg", { payload }); if (error) return { success: false, error: error.message }; revalidatePath("/orgchart"); revalidatePath("/employees"); revalidatePath("/"); return { success: true }; }