'use server';

import { revalidatePath } from 'next/cache';
import { requireAdmin } from '@/lib/auth/current-user';
import { assignPlan, setSubscriptionStatus } from '@/db/admin-queries';
import { tenants } from '@/db/schema';

export async function asignarPlan(formData: FormData) {
  await requireAdmin();
  const tenantId = String(formData.get('tenantId'));
  const planId = String(formData.get('planId'));
  const status = String(formData.get('status')) as (typeof tenants.subscriptionStatus.enumValues)[number];
  await assignPlan(tenantId, planId);
  await setSubscriptionStatus(tenantId, status);
  revalidatePath('/admin/planes');
}
